方式1:docker commit
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
[root@localhost ~]# docker run --net=host -it 5e35e350aded
[root@localhost /]# yum install -y net-tools
...
[root@localhost /]# yum install -y vim
...
[root@localhost /]#
[root@localhost /]# exit
exit
[root@localhost ~]# docker commit infallible_pascal kpioneer/my-centos
sha256:06e5af7d7a7f87e76fd98d3b1410519003e539a6ce8060a9668905bf12964079
[root@localhost ~]#
[root@localhost ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
kpioneer/my-centos latest 06e5af7d7a7f 15 seconds ago 366MB
centos 7 5e35e350aded 3 months ago 203MB
[root@localhost ~]#
[root@localhost ~]# docker history 06e5af7d7a7f
IMAGE CREATED CREATED BY SIZE COMMENT
06e5af7d7a7f 59 seconds ago /bin/bash 163MB
5e35e350aded 3 months ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 3 months ago /bin/sh -c #(nop) LABEL org.label-schema.sc… 0B
<missing> 3 months ago /bin/sh -c #(nop) ADD file:45a381049c52b5664… 203MB
这种方式并不推荐,因为构建的内容不清楚,会造成安全隐患。
方式2:docker build
在 DockerFile文件中 写入
FROM centos
RUN yum install -y vim
保存退出
docker build -t kpioneer/centos-new .
网友评论