@zhaikun
2016-12-28T10:17:09.000000Z
字数 1743
阅读 1066
docker
如果要导出本地某个容器,可以使用 docker export
命令。
[root@zzk ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4d680696fd07 centos "/bin/sh -c 'while tr" 30 minutes ago Exited (137) 20 minutes ago awesome_hoover
0b71bcb30b60 centos "/bin/sh -c 'while tr" 45 minutes ago Exited (137) 40 minutes ago pensive_stallman
87d5008007ec centos "/bin/sh -c 'while tr" 49 minutes ago Exited (137) 48 minutes ago stoic_payne
ddc24a6d00f0 centos "bash" About an hour ago Exited (0) 51 minutes ago modest_gates
7b71848a072a centos "/bin/echo 'Hello wor" About an hour ago Exited (0) About an hour ago big_bell
c4cc44e8870f nginx:1.9 "nginx -g 'daemon off" 3 hours ago Up About an hour 0.0.0.0:80->80/tcp, 443/tcp webserver
edbe3f8b74d1 centos "/bin/bash" 7 hours ago Exited (137) 2 hours ago big_gates
2d8e610dea5c centos "bash" 3 days ago Exited (137) 2 hours ago berserk_payne
46bb9ad81a01 bash "bash" 3 days ago Exited (0) 3 days ago goofy_albattani
ed0595a5ff0e bash "bash" 3 days ago Exited (0) 3 days ago stupefied_albattani
2004577f8837 bash "bash" 3 days ago Exited (0) 3 days ago mad_keller
ef263c4b2603 bash "bash" 3 days ago Exited (0) 3 days ago tiny_keller
6e9df078978c bash "bash" 3 days ago Exited (127) 3 days ago grave_roentgen
0bd749bde8cc 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.0
sha256:082b955dc46cd361299f34f2c9c4de15939f153a48dcb72f0a32d4d88eec88ea
[root@zzk ~]# docker images test/centos:v1.0
REPOSITORY TAG IMAGE ID CREATED SIZE
test/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
来导入一个容器快照到本地镜像库。这两者的区别在于容器快照文件将丢弃所有的历史记录和元数据信息(即仅保存容器当时的快照状态),而镜像存储文件将保存完整记录,体积也要大。此外,从容器快照文件导入时可以重新指定标签等元数据信息。