在使用Docker时最头痛的无非无法获取仓库镜像,我们可以通过Export导出镜像备份,通过import导入镜像。导出镜像是通过容器进行导出,下面来看镜像对应的容器:
root@default:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 94f013c55bc2 boonyadocker/tomcat-allow-remote:latest "/bin/sh -c '/usr/..." 3 weeks ago Up 4 hours 0.0.0.0:50000->50000/tcp, 0.0.0.0:18080->8080/tcp optimistic_fermat aaa1f51447e8 boonyadocker/jenkins:latest "/bin/sh -c '/usr/..." 4 weeks ago Up 4 hours 0.0.0.0:8080->8080/tcp musing_bohr
1、导出容器镜像
sudo docker export optimistic_fermat > tomcat-allow-remote.tar
2、导入容器镜像
cat tomcat-allow-remote.tar | sudo docker import - boonyadocker/tomcat-allow-remote
3、Export Import命令
http://www.runoob.com/docker/docker-export-command.html
http://blog.csdn.net/clj198606061111/article/details/50450793
4、测试示例
(1)以一个导出的tomcat为例:
root@ubuntu:/usr/local/docker/images-tars# ls tomcat-allow-remote.tar root@ubuntu:/usr/local/docker/images-tars# cat tomcat-allow-remote.tar | sudo docker import - boonyadocker/tomcat-allow-remote ae056a538cec95e23dfdb931b7bc7f5b73b6c3f3f4d005b4ff54d392102b2559 root@ubuntu:/usr/local/docker/images-tars# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE boonyadocker/helloworld latest 7e84b0f9c8a3 5 minutes ago 6.839 kB boonyadocker/tomcat-allow-remote latest ae056a538cec 6 minutes ago 558.8 MB hello-world latest 7a5a2d73abce 6 months ago 1.84 kB root@ubuntu:/usr/local/docker/images-tars#
(2)以一个helloworld的打印为例:
root@ubuntu:/home/boonya# ls hello.tar logs rmq_srv_gc.log zookeeper.out root@ubuntu:/home/boonya# docker import - hello.tar ^Z [2]+ Stopped docker import - hello.tar root@ubuntu:/home/boonya# cat hello.tar | sudo docker import - boonyadocker/helloworld:latest e12f05d657006477cb449ee7a99e97ede21b86e2eae80291bdf1b9ce7998f457 root@ubuntu:/home/boonya# sudo docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE boonyadocker/helloworld latest e12f05d65700 16 seconds ago 1.852 kB hello-world latest 7a5a2d73abce 6 months ago 1.84 kB consol/tomcat-7.0 latest 1439b1fbf911 2.179119 years ago 601.3 MB root@ubuntu:/home/boonya#
镜像快速导出导入:
#查看镜像 docker images # 镜像导出 docker save -o your_image_file.tar [image_id] #镜像导入 docker load < your_image_file.tar