镜像的生成途径
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