commit
Description
Create a new image from a container’s changes
Usage
docker commit [OPTIONS] CONTAINER [REPOSITORY][:TAG]
Options
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:
启动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>
镜像制作成功,并可用