Docker save命令用来将指定的镜像导出到宿主机,使用tar.gz格式进行保存。使用“docker save --help”查看帮助信息:
[root@localhost ~]# docker save --help
Usage: docker save [OPTIONS] IMAGE [IMAGE...]
Save one or more images to a tar archive (streamed to STDOUT by default)
Options:
-o, --output string Write to a file, instead of STDOUT其中:
-o, --output string 输出到的文件,替代STDOUT
实例:将ubuntu:15.10镜像保存为ubuntu.tar文件,输出到当前目录。
[root@localhost ~]# docker save -o ubuntu.tar.gz ubuntu:15.10
[root@localhost ~]# ll ubuntu.tar.gz
-rw-------. 1 root root 142986240 Jul 18 10:29 ubuntu.tar.gz
[root@localhost ~]#当然,我们也可以一次输出多个镜像:
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
myimage v1.0 729e175d50db 45 minutes 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
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# docker save -o total.tar.gz ubuntu:15.10 centos:6.7
[root@localhost ~]# ll total.tar.gz
-rw-------. 1 root root 340114432 Jul 18 10:30 total.tar.gz上面将 centos:6.7 和 ubuntu:15.10 镜像一起打包到 total.tar.gz 文件中,该文件的大小是 centos:6.7 和 ubuntu:15.10 文件大小的总和。