基于容器制作
docker commit
`Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]`
(1)Options 参数
-a,作者(例如,“along along@along.com”)
-c,修改Dockerfile指令应用于创建的镜像
-m,提交消息
-p,在提交期间暂停容器(默认为true)
[root@localhost ~]# docker run -it –name a1 busybox /bin/sh
/ # mkdir -p /data/html
/ # echo “<h1>busybox httpd server</h1>” > /data/html/index.html
/ # cat /data/html/index.html
<h1>busybox httpd server</h1>
/ #
将a1 容器制作成镜像
[root@localhost ~]# docker commit -a ‘liuhang’ -m ‘first commit’ a1 liuhang/httpd:v1
sha256:6e70025f5dfaef9a03d33d6f57252d0e86000614eb1c5ff868c817c548091a91
[root@localhost ~]# docker image ls
15291094743/hangliuc/busybox v1 beae173ccac6 2 months ago 1.24MB
[root@localhost ~]# docker run –rm -it liuhang/httpd:v1 /bin/sh
/ # cat /data/html/index.html
<h1>busybox httpd server</h1>
/ # exit
-c 执行指令
基于容器v1创建新的镜像,并修改命令为执行httpd服务
[root@localhost ~]# docker commit -a ‘liuhang’ -m ‘sencond commit’ -c ‘CMD [“/bin/httpd”,”-f”,”-h”,”/data/html”]’ a1 liuhang/httpd:v2
sha256:7a3e6fa0cae7e0750c36a518e447a36d1231e0e16029787e04f323b2886b4775
[root@localhost ~]# docker image ls
liuhang/httpd v2 7a3e6fa0cae7 5 seconds ago 1.24MB
测试:
做端口映射,以便于用外网访问http服务
[root@localhost ~]# docker run -d –name a2 -p 8888:80 liuhang/httpd:v2
86f54a75822f006e90aafd94579935789afb9749de768d9c42265fd25e4b39e6
[root@localhost ~]# docker inspect a2 | grep ‘IPAddress’
“SecondaryIPAddresses”: null,
“IPAddress”: “172.17.0.3”,
“IPAddress”: “172.17.0.3”