[关闭]
@zhaikun 2016-12-28T10:17:09.000000Z 字数 1743 阅读 1066

导出和导入容器

docker


导出容器

如果要导出本地某个容器,可以使用 docker export 命令。

  1. [root@zzk ~]# docker ps -a
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. 4d680696fd07 centos "/bin/sh -c 'while tr" 30 minutes ago Exited (137) 20 minutes ago awesome_hoover
  4. 0b71bcb30b60 centos "/bin/sh -c 'while tr" 45 minutes ago Exited (137) 40 minutes ago pensive_stallman
  5. 87d5008007ec centos "/bin/sh -c 'while tr" 49 minutes ago Exited (137) 48 minutes ago stoic_payne
  6. ddc24a6d00f0 centos "bash" About an hour ago Exited (0) 51 minutes ago modest_gates
  7. 7b71848a072a centos "/bin/echo 'Hello wor" About an hour ago Exited (0) About an hour ago big_bell
  8. 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
  9. edbe3f8b74d1 centos "/bin/bash" 7 hours ago Exited (137) 2 hours ago big_gates
  10. 2d8e610dea5c centos "bash" 3 days ago Exited (137) 2 hours ago berserk_payne
  11. 46bb9ad81a01 bash "bash" 3 days ago Exited (0) 3 days ago goofy_albattani
  12. ed0595a5ff0e bash "bash" 3 days ago Exited (0) 3 days ago stupefied_albattani
  13. 2004577f8837 bash "bash" 3 days ago Exited (0) 3 days ago mad_keller
  14. ef263c4b2603 bash "bash" 3 days ago Exited (0) 3 days ago tiny_keller
  15. 6e9df078978c bash "bash" 3 days ago Exited (127) 3 days ago grave_roentgen
  16. 0bd749bde8cc centos "/bin/bas" 3 days ago Created thirsty_nobel
  17. [root@zzk ~]# docker export ddc24a6d00f0 > centos.tar
  18. [root@zzk ~]#

这样将导入容器快照到本地

导入容器快照

可以使用 docker import 从容器快照文件中再导入为镜像,例如

  1. [root@zzk ~]# cat centos.tar | docker import - test/centos:v1.0
  2. sha256:082b955dc46cd361299f34f2c9c4de15939f153a48dcb72f0a32d4d88eec88ea
  3. [root@zzk ~]# docker images test/centos:v1.0
  4. REPOSITORY TAG IMAGE ID CREATED SIZE
  5. test/centos v1.0 082b955dc46c About a minute ago 191.8 MB
  6. [root@zzk ~]#

此外,也可以通过指定 URL 或者某个目录来导入,例如

  1. $sudo docker import http://example.com/exampleimage.tgz example/imagerepo

:用户既可以使用 docker load 来导入镜像存储文件到本地镜像库,也可以使用 docker import 来导入一个容器快照到本地镜像库。这两者的区别在于容器快照文件将丢弃所有的历史记录和元数据信息(即仅保存容器当时的快照状态),而镜像存储文件将保存完整记录,体积也要大。此外,从容器快照文件导入时可以重新指定标签等元数据信息。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注