Docker-制作镜像-基于容器制作镜像

镜像的生成途径

1、基于容器制作
2、dockerfile,docker bulid

基于容器制作镜像

docker commit
格式:
Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

Options 参数
-a,作者
-c,修改Dockerfile指令应用于创建的镜像
-m,提交消息
-p,在提交期间暂停容器(默认为true)

启动docker服务
[root@KVM02 ~]# systemctl daemon-reload 
[root@KVM02 ~]# systemctl restart docker

运行容器
[root@KVM02 ~]# docker run -it --name b1 busybox /bin/sh
/ # mkdir /data/html
/ # ls /data/
html
/ # echo xx > /data/html/index.html
/ # cat /data/html/index.html 
xx

将当前的容器制作成镜像
[root@KVM02 ~]# docker commit -a 'xx01<2048769943@qq.com>' -m 'first commit' b1 xx01/httpd:v1

查看制作的镜像
[root@KVM02 ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
xx01/httpd          v1                  b5fced4e80ff        7 seconds ago       1.23MB
基于新的镜像运行一个容器,验证是否是基于b1创建成功的
[root@KVM02 ~]# docker run --rm -it xx01/httpd:v1  /bin/sh
/ # cat /data/html/index.html 
xx

基于容器b1创建新的镜像,并修改执行命令CMD
[root@KVM02 ~]# docker commit -a 'xx01<2048769943@qq.com>' -m 'first commit' -c 'CMD ["/bin/httpd","-f","-h","/data/html"]' b1 xx01/httpd:v2
注解:busybox 中httpd 语法
-f:不运行为守护进程,在前台运行
-h:指定httpd运行的主目录

[root@KVM02 ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
xx01/httpd          v2                  d87e2bf8788c        4 seconds ago       1.23MB

将宿主机的端口与容器的80端口进行映射,实现外部访问容器的信息
[root@KVM02 ~]# docker run -d --name b2 -p 8888:8
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值