3.正在运行的容器 docker commit 或者dockerfile build--->镜像,这是容器-->镜像转化和镜像-->镜像。
[root@centos7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hub.c.163.com/library/centos 7.3.1611 67591570dd29 4 years ago 192MB
[root@centos7 ~]# docker run -itd --name centos1 hub.c.163.com/library/centos:7.3.1611
[root@centos7 ~]# docker run -itd --name centos2 hub.c.163.com/library/centos:7.3.1611
[root@centos7 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7d8d950f20b hub.c.163.com/library/centos:7.3.1611 "/bin/bash" 6 minutes ago Up 5 minutes centos2
e20d77bee6af hub.c.163.com/library/centos:7.3.1611 "/bin/bash" 28 minutes ago Up 28 minutes centos1
我现在有一个容器,这个容器名称为hub.c.163.com/library/centos:7.3.1611,执行docker run命令后,生成了两个容器实例,分别名称为centos1和centos2,status栏表明是up状态,也就是运行状态,此时执行docker exec 命令进入任意一个容器,观察ps -ef 可以发现,有一个pid 为1的进程。
[
[
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 08:41 pts/0 00:00:00 /bin/bash
root 14 0 2 08:54 pts/1 00:00:00 /bin/bash
root 27 14 0 08:54 pts/1 00:00:00 ps -ef
那么,如果在容器内没有这个pid 为1的进程,docker会认为这个容器不是在运行的,容器就会停止运行,为什么会有这个/bin/bash pid 为1的进程呢?请看下面的代码:
[root@centos7 ~]# docker history hub.c.163.com/library/centos:7.3.1611
IMAGE CREATED CREATED BY SIZE COMMENT
67591570dd29 4 years ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
missing> 4 years ago /bin/sh -c #(nop) LABEL name=CentOS Base Im… 0B
missing> 4 years ago /bin/sh -c #(nop) ADD file:940c77b6724c00d42… 192MB
missing> 4 years ago /bin/sh -c #(nop) MAINTAINER https://github… 0B
docker commit:
[root@centos7 ~]# docker exec -it centos2 /bin/bash
[root@c7d8d950f20b /]# vim
bash: vim: command not found
[
Loaded plugins: fastestmirror, ovl
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/4): base/7/x86_64/group_gz | 153 kB 00:00:00
(2/4): extras/7/x86_64/primary_db | 222 kB 00:00:00
(3/4): base/7/x86_64/primary_db | 6.1 MB 00:00:07
(4/4): updates/7/x86_64/primary_db | 4.0 MB 00:00:10
Determining fastest mirrors
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.bfsu.edu.cn
Resolving Dependencies
--> Running transaction check
[
[
sha256:8df43092cfd1eb53b895fcda19c9ec0d18c358194045a5fd4d5cf47d177e8b30
4, 查看是否生成新镜像
[
REPOSITORY TAG IMAGE ID CREATED SIZE
centos-vim v1.0 8df43092cfd1 58 seconds ago 332MB
[
85e5a130e4dc1f967534f1e81fba1072f97f81bb1263057e1db0b938b9053323
[
[
[
vim: /usr/bin/vim /usr/share/vim
[root@centos7 ~]# docker history centos-vim:v1.0
IMAGE CREATED CREATED BY SIZE COMMENT
8df43092cfd1 6 minutes ago /bin/bash 140MB
67591570dd29 4 years ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
missing> 4 years ago /bin/sh -c #(nop) LABEL name=CentOS Base Im… 0B
missing> 4 years ago /bin/sh -c #(nop) ADD file:940c77b6724c00d42… 192MB
missing> 4 years ago /bin/sh -c #(nop) MAINTAINER https://github… 0B
docker commit 的弊端:
docker commit的优点:
docker build 方式镜像生成新的镜像:
[
/root/make_vim
[
centos-vimv2.0
2.centos-vim2.0 的内容如下:
FROM hub.c.163.com/library/centos:7.3.1611
RUN yum install -y vim httpd
&& yum clean all
Dockerfile的优点:
Dockerfile的缺点:
版权声明:本文内容来自CSDN:晚风_END,遵循CC 4.0 BY-SA版权协议上原文接及本声明。
本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行可。
原文链接:https://blog.csdn.net/alwaysbefine/article/details/111375658
如有涉及到侵权,请联系,将立即予以删除处理。
在此特别鸣谢原作者的创作。
此篇文章的所有版权归原作者所有,与本公众号无关,商业转载建议请联系原作者,非商业转载请注明出处。