基于容器制作镜像
对容器进行更改从而创建一个新镜像
用法:
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
Options | Default | Description |
---|---|---|
—author, -a | Author (e.g., "John Hannibal Smith hannibal@a-team.com") | |
-c, --change list | 对创建的镜像应用 Dockerfile 指令 | |
-m, --message string | 提交消息 | |
-p, --pause | ture | 在提交期间暂停容器 |
[root@localhost ~]# docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
Digest: sha256:5acba83a746c7608ed544dc1533b87c737a0b0fb730301639a0179f9344b1678
Status: Image is up to date for busybox:latest
docker.io/library/busybox:latest
[root@localhost ~]#
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest beae173ccac6 3 months ago 1.24MB
httpd latest dabbfbe0c57b 4 months ago 144MB
[root@localhost ~]# docker run -it --name b1 busybox
/ # mkdir data
/ # echo 'hello world' > data/index.html
/ # cat /data/index.html
hello world
[root@localhost ~]# docker commit -p b1
sha256:121711e0cdc98ac8573dd7ab953ce66dc6905a787a3965b1e82c5fabf9b23b3e
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 121711e0cdc9 15 seconds ago 1.24MB
busybox latest beae173ccac6 3 months ago 1.24MB
httpd latest dabbfbe0c57b 4 months ago 144MB
[root@localhost ~]# docker tag 121711e0cdc9 busybox:v0.1
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox v0.1 121711e0cdc9 6 minutes ago 1.24MB
busybox latest beae173ccac6 3 months ago 1.24MB
httpd latest dabbfbe0c57b 4 months ago 144MB
[root@localhost ~]# docker tag 121711e0cdc9 xwsxkx/b1:v0.1
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox v0.1 121711e0cdc9 37 minutes ago 1.24MB
xwsxkx/b1 v0.1 121711e0cdc9 37 minutes ago 1.24MB
busybox latest beae173ccac6 3 months ago 1.24MB
httpd latest dabbfbe0c57b 4 months ago 144MB
此时要注意的是,我们的仓库名叫b1,所以我们要在Docker Hub上创建一个名为b1的仓库,然后再将我们做好的镜像push上去
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox v0.1 121711e0cdc9 37 minutes ago 1.24MB
xwsxkx/b1 v0.1 121711e0cdc9 37 minutes ago