首页 > 解决方案 > containerd-shim 如何创建无守护容器?

问题描述

有人指出

垫片允许无守护程序容器。它基本上作为容器进程的父级来促进一些事情。

它保持 STDIO 和其他 fd 为容器打开,以防 containerd 和/或 docker 都死了。如果 shim 没有运行,那么管道的父端或 TTY 主机将关闭,容器将退出。

然而,从进程级别来看,containerd 似乎会产生 containerd-shim,因此如果 containerd 出现故障,我预计 containerd-shim 也会下降。

如果 containerd/docker 宕机了,有人能解释一下 containerd-shim 是如何保持运行的吗?

$ ps fxa | grep dockerd -A 3

     PID TTY      STAT   TIME COMMAND
 43449 pts/2    S+     0:00              \_ grep dockerd -A 3
117536 ?        Ssl  163:36 /usr/bin/containerd
 93633 ?        Sl     1:01  \_ containerd-shim -namespace moby -workdir /var/lib/containerd/io.containerd.runtime.v1.linux/moby/8f75a1b32bb09611430ea55958b11a482b6c83ba2a75f7ca727301eb49a2770f -address /run/containerd/containerd.sock -containerd-binary /usr/bin/containerd -runtime-root /var/run/docker/runtime-runc

$ pstree -lpTs
systemd(1)─┬─VGAuthService(45146)
           ├─accounts-daemon(1053)
           ├─agetty(104696)
           ├─agetty(104707)
           ├─agetty(104716)
           ├─atd(993)
           ├─containerd(117536)─┬─containerd-shim(8394)─┬─bash(8969)
           │                    │                       └─sh(8420)─┬─sshd(8512)
           │                    │                                  └─tail(8514)
           │                    ├─containerd-shim(13170)───bash(13198)
           │                    ├─containerd-shim(13545)───portainer(13577)
           │                    ├─containerd-shim(14156)───mysqld(14184)

...
 ├─dockerd(42320)─┬─docker-proxy(42700)
           │                ├─docker-proxy(42713)
           │                ├─docker-proxy(42725)
           │                ├─docker-proxy(42736)
           │                └─docker-proxy(42749)

更新:根据接受的答案中提供的解释:

$ pstree -lpTs
systemd(1)─┬─VGAuthService(45146)
           ├─accounts-daemon(1053)
           ├─agetty(104696)
           ├─agetty(104707)
           ├─agetty(104716)
           ├─atd(993)
           ├─containerd(117536)─┬─containerd-shim(8394)─┬─bash(8969)
           │                    │                       └─sh(8420)─┬─sshd(8512)
           │                    │                                  └─tail(8514)
           │                    ├─containerd-shim(13170)───bash(13198)
           │                    ├─containerd-shim(13545)───portainer(13577)
           │                    ├─containerd-shim(14156)───mysqld(14184)

$ sudo kill -9 117536

$ pstree -lpTs
systemd(1)─┬─VGAuthService(45146)
           ├─accounts-daemon(1053)
           ├─agetty(104696)
           ├─agetty(104707)
           ├─agetty(104716)
           ├─atd(993)
           ├─containerd-shim(8394)─┬─bash(8969)
           │                       └─sh(8420)─┬─sshd(8512)
           │                                  └─tail(8514)
           ├─containerd-shim(13170)───bash(13198)
           ├─containerd-shim(13545)───portainer(13577)
           ├─containerd-shim(14156)───mysqld(14184)

标签: docker

解决方案


然而,从进程级别来看,containerd 似乎会产生 containerd-shim,因此如果 containerd 出现故障,我预计 containerd-shim 也会下降。

当父进程死亡时,子进程不会自动死亡,它们只是重新设置为 PID 1。systemd作为父进程接管并containerd-shim继续运行。


推荐阅读