如果想要把镜像存出到本地文件,可以使用docker save命令,例如,存出本地的刚才创建的testimage:lastest为镜像文件testimage.tar文件:
docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
testimage latest baea98d5a437 25 minutes ago 188.3 MB
ubuntu latest fa81ed084842 3 days ago 188.3 MB
….
docker save –o /data/testimage.tar testimage:latest
上面的第6行就是存出代码,这时在/data下就有一个testimage.tar文件,这时我们把本地镜像rmi掉,然后尝试载入。
载入镜像
删除镜像之后的状态:
ubuntu@VM–223–238–ubuntu:/data$ docker rmi baea98d5a437Untagged: testimage:latest
Deleted: baea98d5a4371a6abf9efc8c53a54a6fc5befd167bf91ce9fd4a28a6d1b7dc5b
ubuntu@VM–223–238–ubuntu:/data$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 14.04 ab80404d13d5 5 minutes ago 215.4 MB
然后载入镜像:
docker load —input testimage.tardocker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 14.04 ab80404d13d5 6 minutes ago 215.4 MB
testimage latest baea98d5a437 35 minutes ago 188.3 MB
第一行就是载入镜像,还可以简化写成:
docker load —input testimage.tardocker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 14.04 ab80404d13d5 6 minutes ago 215.4 MB
testimage latest baea98d5a437 35 minutes ago 188.3 MB
载入操作将会导入镜像以及相关的元数据信息(包括标签等)。
镜像的上传
最后说点镜像的上传,镜像的管理方式非常像git,可以使用docker push命令上传自己本地镜像到仓库,默认上传到DockerHub官方仓库(需要登陆),命令格式:
docker push NAME[:TAG]在上传之前一般会先为自己的镜像添加带自己名字(作者信息)的标签:
docker tag testimage:lastest zmc/testimage:lastestdocker pushzmc/testimage:lastest
有利于上传之后的区分。
我觉得无论是运维团队还是开发团队还是一个实验室,都有必要有一个自己的Docker仓库,可以存放符合自己需求的环境或系统镜像,可以实现快速部署。
您可能感兴趣的文章:Docker创建镜像、怎么修改、上传镜像等详细介绍Docker创建镜像两种方法详解详解nodejs之创建最小docker镜像详解Docker学习之用commit命令创建镜像创建Web项目的Docker镜像实例讲解Docker使用Dockerfile来创建镜像详解docker中Dockerfile指令创建镜像










