docker启动流程

amd-container-runtime的作用

daemon.json配置

xtubk@rocm2404:~/package/amd-continer$ cat /etc/docker/daemon.json
{
    "features": {
        "cdi": true
    },
    "registry-mirrors": [
        "https://0dj0t5fb.mirror.aliyuncs.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://6kx4zyno.mirror.aliyuncs.com",
        "https://registry.docker-cn.com"
    ],
    "runtimes": {
        "amd": {
            "args": [],
            "path": "/data/users/like/package/amd-continer/amd-container-runtime"
        }
    }
}

代码仓库

https://github.com/ROCm/container-toolkit

amd-container-runtime是谁启动的

/usr/bin/containerd-shim-runc-v2
amd-container-runtime: 64747
 pid:64747, ppid:64736
xtubk@rocm2404:~$ ps aux | grep 64736
root       64736  0.0  0.0 1238104 14336 ?       Sl   10:23   0:00 /usr/bin/containerd-shim-runc-v2 -namespace moby -id 27f1c7ccf6cefd6c47e3388be247ed83ef46333230f1a01a722eb5a763dde323 -address /run/containerd/containerd.sock

/usr/bin/containerd-shim-runc-v2是谁启动的:

deepseek答案:
containerd-shim-runc-v2 进程的启动和与 systemd 的关系可以通过以下关键点说明:

‌启动流程‌
当 containerd 收到创建容器的请求时,会先启动 containerd-shim 进程,再由该进程启动 /usr/bin/containerd-shim-runc-v2。随后,初始的 containerd-shim 进程退出,containerd-shim-runc-v2 的父进程变为 systemd(1)(即系统的 init 进程)。这种设计确保了容器运行时与 containerd 解耦,即使 containerd 退出也不会影响容器运行‌12。

‌与 systemd 的关系‌
containerd-shim-runc-v2 并非直接由 systemd 的 unit 文件启动,而是通过 containerd 的调用间接生成。但由于其父进程在初始 containerd-shim 退出后变为 systemd(1),因此从进程树视角看,它最终由 systemd 托管‌12。

‌设计目的‌
这种机制的核心是避免 containerd 成为容器进程的直接父进程,从而提升容器的独立性。containerd-shim-runc-v2 会持续监控容器状态并清理僵尸进程,其托管给 systemd 的特性进一步增强了稳定性‌13。

总结来说,containerd-shim-runc-v2 的启动链为 containerd → containerd-shim → containerd-shim-runc-v2,最终由 systemd 接管其父进程角色,但并非直接通过 systemd 的配置启
deepseek参考:
https://www.cnblogs.com/daemon365/p/17764879.html

每个containerd-shim-runc-v2对应一个容器:

xtubk@rocm2404:~$ ps -eo pid,ppid,cmd | grep containerd-shim
  60204       1 /usr/bin/containerd-shim-runc-v2 -namespace moby -id 7eea8ca8a5f9dbbd914fd58bc8fe81c73095cb0bcc92c54503d3379a703c4a63 -address /run/containerd/containerd.sock
  60361       1 /usr/bin/containerd-shim-runc-v2 -namespace moby -id c9ae6fbb0955dac23a6cd581a13d0125216fed4247ba791f14528d186b7ef629 -address /run/containerd/containerd.sock
  64736       1 /usr/bin/containerd-shim-runc-v2 -namespace moby -id 27f1c7ccf6cefd6c47e3388be247ed83ef46333230f1a01a722eb5a763dde323 -address /run/containerd/containerd.sock

amd-container-runtime会调用 runc

在internal/runtime/runtime.go里面

RUNC = "runc"
runc, err := exec.LookPath(RUNC)
err = syscall.Exec(runc, rt.args, os.Environ())

dockerd是来自哪个仓库

https://github.com/moby/moby.git

Leave a Comment