docker save
-
docker save centos:self -o centos.tar
导出镜像到文件 - 用于持久化镜像,导出的tar包需要用
docker load -i imagedata.tar
导入 - 会将镜像的所有layer导出,导出的文件会比较大。
-
docker load
不可指定镜像名和tar。docker import
可以指定镜像名和tar - 可用
docker history 8652b9f0cb4c
查看镜像的layer[root@twilight0319 ~]# docker history centos:self IMAGE CREATED CREATED BY SIZE COMMENT c9dfc8a523b0 6 minutes ago bash 87.5MB <missing> 3 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B <missing> 3 weeks ago /bin/sh -c #(nop) LABEL org.label-schema.sc… 0B <missing> 3 weeks ago /bin/sh -c #(nop) ADD file:b3ebbe8bd304723d4… 204MB
docker export
-
docker export containerid> dockertest.tar
导出容器,导入后又会变成镜像 - 用于持久化容器。导出成tar包需要用
docker import
导入-
docker import dockertest.tar -- centos:111
或者cat dockertest.tar | docker import - imagename:tag
-
- 丢失所有元数据,只保存虚拟机的当前状态。
[root@twilight0319 ~]# docker history centos:111 IMAGE CREATED CREATED BY SIZE COMMENT ef0539471f16 45 seconds ago 267MB Imported from -
坑
这四个命令的对应关系不可出错,否则,会出现奇怪的问题比如:
这东西真是巨坑
Error response from daemon: OCI runtime create failed: container_linux.go:349 : starting container process caused "exec: \"bash\": executable file not found in $PATH": unknown
- 转移镜像:
docker save imagename:tag -o imagedata.tar
和docker load -i imagedata.tar
- 转移容器:
docker export containerid> dockertest.tar
和docker import dockertest.tar -- imagename:tag
OCI runtime create failed: container_linux.go:349 : starting container process caused “exec: “bash