1、概述docker
建立镜像有两种方法,一是用commit命令,二是用dockerfile方法(这个更经常使用,在下面文章介绍)。本章介绍commit方法。shell
在介绍commit命令前,咱们先回顾下对代码的版本控制,当修改代码后,咱们会commit变动到版本服务器上。ubuntu
对于容器相似的概念,当建立容器后,若是后面对容器作了修改,就能够利用commit命令将修改提交为一个新的镜像。bash
2、例子说明服务器
下面咱们经过具体的例子来讲明:spa
一、建立新容器版本控制
docker run --name newcontent -i -t ubuntu /bin/bashcode
二、进行操做,修改容器内容blog
echo hello world >>test.txt //经过重定向功能建立一个文件dockerfile
三、退出shell,容器关闭
四、用diff命令查看容器的变化信息
xxx@ubuntu:~$ docker diff newcontent C /root A /root/.bash_history A /test.txt
五、建立新镜像
docker commit newcontent newnewcontent2
这时就在本地建立了一个仓库名为newnewcontent2,tag值为默认为latest的镜像。
规范的镜像名应该为:
[username/]repositoryName[:tagName]
如:docker commit newcontent jeme/myubuntu:1.0
若是没有tagName,则默认为latest。
注意:若是须要把该镜像提交到dokcer hub中心,则必须规范命名(必须是 用户名/仓库名,tag能够缺省),前面的用户名是在dokcer hub上注册的用户名。
3、删除本地镜像
docker rmi 镜像名/ID