Docker 制作镜像

基于容器制作
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"
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值