docker - 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)
解决方案
然而,从进程级别来看,containerd 似乎会产生 containerd-shim,因此如果 containerd 出现故障,我预计 containerd-shim 也会下降。
当父进程死亡时,子进程不会自动死亡,它们只是重新设置为 PID 1。systemd
作为父进程接管并containerd-shim
继续运行。
推荐阅读
- html - 旋转元素时,具有透明背景的 div 中出现意外的灰线
- python - 如何在 Jupyter Notebook 单元格中刷新 Python 导入?
- java - java模块问题“模块'mp3player'从'javafx.graphics'和'javafx.graphics'读取包'javafx.animation'”
- python - 从 Python 中的嵌套列表中获取一个集合
- python - FileNotFoundError:[Errno 2] 没有这样的文件或目录:hparams.json
- c# - Blazor WASM Cookie 身份验证 .NET5
- node.js - 使用 GRPC 接口获取比特币现金钱包地址的交易事件
- ios - iOS AVFoundation:获取 AVCaptureDevice.Format 的视频尺寸
- python - 辩护中的论点
- c# - UWP 计算器难度