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