03-2 docker镜像管理之镜像的导出、导入

03-2 docker镜像管理之镜像的导出、导入

  1. 导出镜像:docker save

    docker save [命令参数][导出镜像名称(可自定义)][本地镜像的名称]
    

    将已经下载好的镜像,导出到本地,以备后用

    # 作用:将本地的一个或多个镜像打包保存成本地tar文件
    # 命令格式:
    docker save [命令参数][导出镜像名称(可自定义)][本地镜像的名称]
    # 导出镜像,注意这里的yasuo_ubuntu.tar是压缩文件的名称,被压缩的文件没有发生改变仍然是ubuntu,导出文件默认存储于当前目录下
    
    # 查看本地所有镜像
    qwe@ubuntu:~$ docker image ls -a
    REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
    ubuntu                latest              d70eaf7277ea        10 days ago         72.9MB
    hyperledger/caliper   0.4.0               6491b4ec891d        4 weeks ago         356MB
    hello-world           latest              bf756fb1ae65        10 months ago       13.3kB
    
    # 把ubuntu导出为压缩文件
    qwe@ubuntu:~$ docker save -o yasuo_ubuntu.tar ubuntu
    
    # 查看导出的yasuo_ubuntu.tar
    qwe@ubuntu:~$ ls
    Desktop    Downloads  Pictures  Templates  a.txt               examples.desktop
    Documents  Music      Public    Videos     caliper-benchmarks  yasuo_ubuntu.tar
    
    

    命令参数(OPTIONS):
    -o, --output string 指定写入的文件名和路径

  2. 导入镜像:docker load

    docker load [命令参数][被导入镜像压缩文件的名称]
    docker load < [被导入镜像压缩文件的名称]
    docker load --input [被导入镜像压缩文件的名称]
    
    #作用:将save命令打包的镜像导入本地镜像库中
    #导入镜像命令格式:
    docker load [命令参数][被导入镜像压缩文件的名称]
    docker load < [被导入镜像压缩文件的名称]
    docker load --input [被导入镜像压缩文件的名称]
    
    #为了更好的演示效果,我们先将本地的ubuntu镜像删除掉
    qwe@ubuntu:~$ docker rmi ubuntu:latest 
    Untagged: ubuntu:latest
    Untagged: ubuntu@sha256:fff16eea1a8ae92867721d90c59a75652ea66d29c05294e6e2f898704bdb8cf1
    Deleted: sha256:d70eaf7277eada08fca944de400e7e4dd97b1262c06ed2b1011500caa4decaf1
    Deleted: sha256:778d52487737cf5362fd95086fa55793001dbc7b331344a540a594824e2994fd
    Deleted: sha256:7011438f48b79cbf5fce3bfba74aed2e53fe5fe6a3b7fd6fe03018d28caee7a3
    Deleted: sha256:47dde53750b4a8ed24acebe52cf31ad131e73a9611048fc2f92c9b6274ab4bf3
    
    # 检查本地ubuntu删除成功
    qwe@ubuntu:~$ docker images
    REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
    hyperledger/caliper   0.4.0               6491b4ec891d        4 weeks ago         356MB
    hello-world           latest              bf756fb1ae65        10 months ago       13.3kB
    
    # 导入镜像文件:
    qwe@ubuntu:~$ docker load < yasuo_ubuntu.tar 
    47dde53750b4: Loading layer  75.25MB/75.25MB
    0c2689e3f920: Loading layer  15.36kB/15.36kB
    cc9d18e90faa: Loading layer  3.072kB/3.072kB
    Loaded image: ubuntu:latest
    
    # 镜像文件ubuntu:latest导入成功
    qwe@ubuntu:~$ docker images
    REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
    ubuntu                latest              d70eaf7277ea        10 days ago         72.9MB
    hyperledger/caliper   0.4.0               6491b4ec891d        4 weeks ago         356MB
    hello-world           latest              bf756fb1ae65        10 months ago       13.3kB
    
    
    
    

注意:

  1. 如果发现导入的时候没有权限需要使用chmod命令修改镜像文件的权限

  2. 命令参数(OPTIONS):
    -i, --input string 指定要打入的文件,如没有指定,默认是STDIN

posted @ 2020-11-03 14:59  TR_Goldfish  阅读(497)  评论(0编辑  收藏  举报