Docker 镜像和容器的导入导出
一、镜像的导出和导入
1.镜像的保存
[root@k8s-master ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest ae513a47849c 2 months ago 109MB debian jessie 4eb8376dc2a3 2 months ago 127MB rabbitmq 3.6.8 8cdcbee37f62 15 months ago 179MB [root@k8s-master tmp]# docker save ae513a47849c > nginx-save.tar [root@k8s-master tmp]# ls -lh total 108M -rw-r--r-- 1 root root 108M Jul 4 09:32 nginx-save.tar
2.镜像的导入
可以将导出的nginx-save.tar包传到需要的docker主机上面,然后执行导入命令.
[root@k8s-master tmp]# ls -lh total 108M -rw-r--r-- 1 root root 108M Jul 4 09:32 nginx-save.tar [root@k8s-master tmp]# docker load < nginx-save.tar 82b81d779f83: Loading layer [==================================================>] 54.21MB/54.21MB 7ab428981537: Loading layer [==================================================>] 3.584kB/3.584kB Loaded image ID: sha256:ae513a47849c895a155ddfb868d6ba247f60240ec8495482eca74c4a2c13a881
二、容器的导出和导入
1.容器的导出
[root@k8s-master tmp]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 220aee82cfea tomcat:7 "catalina.sh run" 9 seconds ago Up 7 seconds 8080/tcp tomcat7 [root@k8s-master tmp]# docker export 220aee82cfea > tomcat-export.tar [root@k8s-master tmp]# ls -lh total 447M -rw-r--r-- 1 root root 339M Jul 4 10:05 tomcat-export.tar
2.容器的导入
[root@k8s-master tmp]# docker import tomcat-export.tar sha256:47d9f45f739a4833be3be004fc58aed96728071b465d2b30351f3d047415e89f [root@k8s-master tmp]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> 47d9f45f739a 47 seconds ago 345MB [root@k8s-master tmp]# docker tag 47d9f45f739a tomcat7:export [root@k8s-master tmp]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE tomcat7
镜像和容器 导出和导入的区别:
1.镜像导入 是复制的过程
2.容器导入 是将当前容器 变成一个新的镜像
save 和 export区别:
1)save 保存镜像所有的信息-包含历史
2)export 只导出当前的信息
参考文档:https://www.jianshu.com/p/8408e06b7273