离线部署docker中的containerd服务

containerd 是一个行业标准的容器运行时,专注于简单、健壮的容器执行。它是从 Docker 中分离出来的项目,旨在作为一个底层的运行时接口,供更高层次的容器管理层使用。

containerd 负责镜像传输、存储、容器执行、网络配置等工作。它向上为 Docker 等高级容器管理层提供 API 接口,向下则直接调用操作系统内核特性或通过 runC 来运行容器。

containerd.sock 是由 containerd 自动创建的,前提是 containerd 已经被正确安装、配置并启动。

Docker 使用 containerd 作为其容器运行时的一部分。当你通过 Docker CLI 或 API 发出命令时,这些命令会首先到达 Docker 守护进程(docker daemon),然后 Docker 守护进程可能会通过 gRPC 接口将具体的容器运行任务委派给 containerd 来执行。

1.离线部署docker

详见离线安装 docker 和 docker-compose

2.配置文件

sudo mkdir -p /etc/containerd/

containerd config default | sudo tee /etc/containerd/config.toml

3.系统服务

下载:

https://raw.githubusercontent.com/containerd/containerd/main/containerd.service

cp containerd.service /etc/systemd/system/

chmod +x /etc/systemd/system/containerd.service

复制代码
# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target dbus.service

[Service]
#uncomment to enable the experimental sbservice (sandboxed) version of containerd/cri integration
#Environment="ENABLE_CRI_SANDBOXES=sandboxed"
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerd

Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# 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
LimitNOFILE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999

[Install]
WantedBy=multi-user.target

Description:

提供了对该服务单元的简短描述。

在这个例子中,描述为 "containerd container runtime",表示这是一个用于容器运行的 containerd 服务。
Documentation:

提供了指向官方文档的链接,帮助用户了解更多信息。

在这个例子中,链接指向 https://containerd.io
After:

指定了在启动此服务之前需要启动的其他服务或目标(target)。

在这个例子中,containerd 将在网络 (network.target)、本地文件系统 (local-fs.target) 和 D-Bus (dbus.service) 启动之后再启动。
ExecStartPre:

在启动主进程之前执行的命令。

-/sbin/modprobe overlay 表示尝试加载内核模块 overlay,前面的 - 表示即使该命令失败也不会阻止服务启动。
ExecStart:

指定要启动的主进程命令。

/usr/bin/containerd 是 containerd 守护进程的可执行文件路径。
Type:

定义了服务的启动类型。

notify 表示 containerd 将通过 sd_notify(3) 协议通知 systemd 其启动状态。
Delegate:

允许 containerd 管理自己的 cgroup 层次结构。

yes 表示启用这种行为。
KillMode:

定义了当停止服务时应终止哪些进程。

process 表示仅终止主进程。
Restart:

定义了服务失败时是否以及如何重启。

always 表示无论退出代码是什么,都会重启服务。
RestartSec:

定义了在服务失败后等待多久进行重启。

5 表示等待 5 秒后再重启。

LimitNPROC, LimitCORE, LimitNOFILE:

设置了对进程数、核心转储大小和打开文件描述符数量的限制。

infinity 表示没有限制。
TasksMax:

设置了服务可以创建的最大任务数。

infinity 表示没有限制,但需注意只有 systemd 226 及以上版本支持此设置。
OOMScoreAdjust:

调整服务的 OOM(Out of Memory)分数。

-999 表示尽量避免在内存不足时杀死该服务。
WantedBy:

指定了在哪些目标(target)下该服务单元会被自动启动。

在这个例子中,multi-user.target 是一个常见的 systemd target,代表多用户模式(即非图形界面的完整系统启动状态)。这意味着当你运行 systemctl enable containerd.service 时,containerd 服务将在系统进入多用户模式时自动启动。

4.启动服务

sudo systemctl daemon-reload

sudo systemctl start containerd

​​​​​​​5.设置开机启动

sudo systemctl enable containerd

​​​​​​​6.服务状态

sudo systemctl status containerd

相关推荐
RationalDysaniaer36 分钟前
k8s配置与存储
云原生·容器·kubernetes
ybb7046304 小时前
linux第二次作业
linux·运维·服务器
大白同学4215 小时前
【Linux】进程间通信
linux·运维·服务器
..Move...6 小时前
Docker镜像制作
运维·docker·容器
码龄3年 审核中11 小时前
说说SSH的端口转发
大数据·运维·ssh
盛世隐者11 小时前
【Linux】定制Linux系统
linux·运维·服务器
行思理12 小时前
Docker 应该如何学习 分四个阶段
学习·docker·容器
..Move...13 小时前
Docker应用部署tomcat和nginx
nginx·docker·tomcat
Lxt.星翊14 小时前
MySQL(安装和卸载、数据库存储原理图)
linux·运维·windows
苹果醋314 小时前
JAVA面试汇总(二)多线程(五)
运维·vue.js·spring boot·nginx·课程设计