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> 镜像制做成功,并可用