Create a new image from a container’s changeshtml
docker commit [OPTIONS] CONTAINER [REPOSITORY][:TAG]
Name,shorthand | Default | Description |
---|---|---|
--author , -a | Author (e.g., 「John Hannibal Smith hannibal@a-team.com」) | |
--change , -c | Apply Dockerfile instruction to the created image | |
--message , -m | Commit messae | |
--pause , -p | true | Pause container during commit |
ex:docker
啓動busybox服務,由於busybox沒有服務啓動於前臺,因此必須與其交互(sh)。因此要在busybox中啓動httpd服務 ~]# docker run --name b1 -it docker.io/busybox / # mkdir -p /app/www/ / # echo "<h1>Hello World!</h1>" > /app/www/index.html / # /bin/httpd -f -h /app/www/ httpd -f(啓動於前臺),-h,服務頁面路徑地址 切換至另外一個終端,並製做新的images ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/busybox latest f6e427c148a7 2 weeks ago 1.15 MB [root@centos7 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f10f16279840 docker.io/busybox "sh" 13 minutes ago Up 12 minutes b1 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/xiaoniaoo/dm v1.0.1-bhttpd 5c1d55da33fd 48 minutes ago 1.15 MB docker.io/busybox latest f6e427c148a7 2 weeks ago 1.15 MB ~]# docker commit -a "<xiaoniaoo>" -p -c='CMD ["/bin/httpd","-f","-h","/app/www/"]' b1 docker.io/xiaoniaoo/dm:v1.0.1-shttpd ~]# docker push docker.io/xiaoniaoo/dm:v1.0.1-shttpd 在另外一臺機器上,拉鏡像並啓動,看httpd服務是否啓動並剝離終端 ~]# docker run --name bh -d docker.io/xiaoniaoo/dm:v1.0.1-shttpd ~]# docker inspect bh ~]# curl http://172.17.0.2 <h1>Dai</h1> 鏡像製做成功,並可用