@zhaikun
2016-12-28T02:17:09.000000Z
字数 1743
阅读 1211
docker
如果要导出本地某个容器,可以使用 docker export 命令。
[root@zzk ~]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES4d680696fd07 centos "/bin/sh -c 'while tr" 30 minutes ago Exited (137) 20 minutes ago awesome_hoover0b71bcb30b60 centos "/bin/sh -c 'while tr" 45 minutes ago Exited (137) 40 minutes ago pensive_stallman87d5008007ec centos "/bin/sh -c 'while tr" 49 minutes ago Exited (137) 48 minutes ago stoic_payneddc24a6d00f0 centos "bash" About an hour ago Exited (0) 51 minutes ago modest_gates7b71848a072a centos "/bin/echo 'Hello wor" About an hour ago Exited (0) About an hour ago big_bellc4cc44e8870f nginx:1.9 "nginx -g 'daemon off" 3 hours ago Up About an hour 0.0.0.0:80->80/tcp, 443/tcp webserveredbe3f8b74d1 centos "/bin/bash" 7 hours ago Exited (137) 2 hours ago big_gates2d8e610dea5c centos "bash" 3 days ago Exited (137) 2 hours ago berserk_payne46bb9ad81a01 bash "bash" 3 days ago Exited (0) 3 days ago goofy_albattanied0595a5ff0e bash "bash" 3 days ago Exited (0) 3 days ago stupefied_albattani2004577f8837 bash "bash" 3 days ago Exited (0) 3 days ago mad_kelleref263c4b2603 bash "bash" 3 days ago Exited (0) 3 days ago tiny_keller6e9df078978c bash "bash" 3 days ago Exited (127) 3 days ago grave_roentgen0bd749bde8cc centos "/bin/bas" 3 days ago Created thirsty_nobel[root@zzk ~]# docker export ddc24a6d00f0 > centos.tar[root@zzk ~]#
这样将导入容器快照到本地
可以使用 docker import 从容器快照文件中再导入为镜像,例如
[root@zzk ~]# cat centos.tar | docker import - test/centos:v1.0sha256:082b955dc46cd361299f34f2c9c4de15939f153a48dcb72f0a32d4d88eec88ea[root@zzk ~]# docker images test/centos:v1.0REPOSITORY TAG IMAGE ID CREATED SIZEtest/centos v1.0 082b955dc46c About a minute ago 191.8 MB[root@zzk ~]#
此外,也可以通过指定 URL 或者某个目录来导入,例如
$sudo docker import http://example.com/exampleimage.tgz example/imagerepo
注:用户既可以使用 docker load 来导入镜像存储文件到本地镜像库,也可以使用 docker import 来导入一个容器快照到本地镜像库。这两者的区别在于容器快照文件将丢弃所有的历史记录和元数据信息(即仅保存容器当时的快照状态),而镜像存储文件将保存完整记录,体积也要大。此外,从容器快照文件导入时可以重新指定标签等元数据信息。