Containerd 是一个工业级标准的容器运行时,它强调简单性、健壮性和可移植性。Containerd 可以在宿主机中管理完整的容器生命周期:容器镜像的传输和存储、容器的执行和管理、存储和网络等。详细点说,Containerd 负责干下面这些事情:
Containerd 被设计成嵌入到一个更大的系统中,而不是直接由开发人员或终端用户使用。
Containerd 被设计成嵌入到一个更大的系统中,而不是直接由开发人员或终端用户使用。所以 containerd 具有宏大的愿景(此图来自互联网):
里提到了通过,他们将 containerd 设计成了 snapshotter 的模式,这也使得 containerd 对于 overlay 文件系、snapshot 文件系统的支持比较好。
》。
,当前的最新版本为 v1.1.0。
[Service]
ExecStartPre=/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd
Delegate=yes
KillMode=process
LimitNOFILE=1048576
Having non-zero Limit*s causes performance problems due to accounting overhead
in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
[Install]
WantedBy=multi-user.target
<span style="color: #800000">"<span style="color: #800000">log<span style="color: #800000">"
<span style="color: #800000">"<span style="color: #800000">github.com/containerd/containerd<span style="color: #800000">"<span style="color: #000000">
)
func main() {
<span style="color: #0000ff">if err := redisExample(); err !=<span style="color: #000000"> nil {
log.Fatal(err)
}
}
func redisExample() error {
client,err := containerd.New(<span style="color: #800000">"<span style="color: #800000">/run/containerd/containerd.sock<span style="color: #800000">"<span style="color: #000000">)
<span style="color: #0000ff">if err !=<span style="color: #000000"> nil {
<span style="color: #0000ff">return<span style="color: #000000"> err
}
defer client.Close()
<span style="color: #0000ff">return<span style="color: #000000"> nil
}
》一文中介绍的 "created"。这意味着 namespaces、rootfs 和容器的配置都已经初始化成功了,只是用户进程(这里是 redis-server)还没有启动。在这个时机,我们可以为容器设置网卡,还可以配置工具来对容器进行监控等。
<span style="color: #0000ff">return<span style="color: #000000"> err
}
status := <-<span style="color: #000000">exitStatusC
code,exitedAt,err :=<span style="color: #000000"> status.Result()
<span style="color: #0000ff">if err !=<span style="color: #000000"> nil {
<span style="color: #0000ff">return<span style="color: #000000"> err
}
fmt.Printf(<span style="color: #800000">"<span style="color: #800000">redis-server exited with status: %d\n<span style="color: #800000">",code)
。下面编译 demo 代码并运行: