docker load 命令将使用 docker save 命令导出的 tar 导入到 docker 当中。帮助信息如下:
[root@localhost ~]# docker load --help Usage: docker load [OPTIONS] Load an image from a tar archive or STDIN Options: -i, --input string Read from tar archive file, instead of STDIN -q, --quiet Suppress the load output
其中:
-i, --input string 指定要导入的tar文件路径,替代STDIN
-q, --quiet 精简加载tar文件的输出信息
实例:首先查看当前docker中存在哪些镜像。如下:
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE myimage v1.0 729e175d50db 25 hours ago 468MB ubuntu latest 4c108a37151f 4 weeks ago 64.2MB centos 6.7 9f1de3c6ad53 4 months ago 191MB centos latest 9f38484d220f 4 months ago 202MB ubuntu 15.10 9b9cb95443b5 2 years ago 137MB
将“ubuntu:15.10”镜像导出为 ubuntu.tar 文件,如下:
[root@localhost ~]# docker save -o ubuntu.tar ubuntu:15.10 [root@localhost ~]# ll ubuntu.tar -rw-------. 1 root root 142986240 Jul 19 10:56 ubuntu.tar
使用“docker rmi”将现在docker中的“ubuntu:15.10”镜像删除。如下:
[root@localhost ~]# docker rmi ubuntu:15.10 Untagged: ubuntu:15.10 Untagged: ubuntu@sha256:02521a2d079595241c6793b2044f02eecf294034f31d6e235ac4b2b54ffc41f3 Deleted: sha256:9b9cb95443b5f846cd3c8cfa3f64e63b6ba68de2618a08875a119c81a8f96698 Deleted: sha256:b616585738eaf78ff7d86c7526caf7c91a35bc4028ef63204e5bfee82f7494b5 Deleted: sha256:dee1316f97acc7e1a5088b02fbc2b3078e0bfa038dd904b8072e2de5656e7bb8 Deleted: sha256:e7d9ae1a69c53c9fefa1aef34348be5a5dbf2fe79e7dd647b3d4f4e927587ebc Deleted: sha256:f121afdbbd5dd49d4a88c402b1a1a4dca39c9ae75ed7f80a29ffd9739fc680a7
上面通过docker rmi已经将镜像“ubuntu:15.10”彻底删除。这里我们使用“docker load”将导出的tar文件加载到docker。如下:
[root@localhost ~]# docker load -i ubuntu.tar f121afdbbd5d: Loading layer [===========================================>] 142.9MB/142.9MB 4b955941a4d0: Loading layer [===========================================>] 15.87kB/15.87kB af288f00b8a7: Loading layer [===========================================>] 11.78kB/11.78kB 98d59071f692: Loading layer [===========================================>] 4.608kB/4.608kB Loaded image: ubuntu:15.10 [root@localhost ~]# docker images ubuntu:15.10 REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu 15.10 9b9cb95443b5 2 years ago 137MB