保存镜像文件或容器作为一个压缩的文件,和别人进行共享。
导出一个容器作为一个tar文件。
[[email protected] ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8c892f17fc59 ubuntu:14.04 "/bin/bash" 6 minutes ago Exited (0) 5 minutes ago adoring_ardinghelli
90d654f31d93 ubuntu:14.04 "sleep 360" 4 hours ago Exited (0) 4 hours ago testcopy
5a5d99af6149 ubuntu:14.04 "/bin/bash" 5 hours ago Exited (0) 5 hours ago heuristic_torvalds
feff1c794224 ubuntu:14.04 "/bin/bash" 5 hours ago Exited (0) 5 hours ago data
b2913d513319 mysql "docker-entrypoint.s…" 5 hours ago Up 5 hours 3306/tcp mysqlwp
[[email protected] ~]# docker export 8c8 > update.tar
[[email protected] ~]# ll
total 190652
-rw-r--r-- 1 root root 195227136 May 27 15:13 update.tar
我们把导出的容器复制到192.168.20.121这个主机上去,然后进行导入。
[[email protected] ~]# scp update.tar [email protected]:/root
update.tar
[[email protected] ~]# docker import - update < update.tar
sha256:ba68497253af98610ccba424463f0b867a21af69589cc7e0618b5b1db8771639
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
update latest ba68497253af 7 seconds ago 186MB
以上步骤也可以使用save和Load选项,可以达到同样的效果。
[[email protected] ~]# docker save -o update1.tar update
[[email protected] ~]# docker rmi update
Untagged: update:latest
Deleted: sha256:ba68497253af98610ccba424463f0b867a21af69589cc7e0618b5b1db8771639
Deleted: sha256:162b149483cd0d3786732c9012a24d21b2b81c404d45b6e1a99dc5ccf17f08c9
[[email protected] ~]# docker load < update1.tar
162b149483cd: Loading layer [==================================================>] 195.2MB/195.2MB
Loaded image: update:latest
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
update latest ba68497253af 4 minutes ago 186MB
save& load 和export & improt两个方法结果都是一样的。
技术讨论群:190029784
原文地址:http://blog.51cto.com/aishangwei/2120805
时间: 2024-10-09 18:50:07