离线部署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

相关推荐
EasyNVR2 分钟前
docker版EasyNVR如何使用同步插件教程(包含网盘挂载,路径映射等)
docker·容器·音视频
岁岁种桃花儿28 分钟前
详解kubectl get replicaset命令及与kubectl get pods的核心区别
运维·nginx·容器·kubernetes·k8s
捷智算云服务31 分钟前
告别运维割裂!捷智算GPU维修中心重新定义“全栈式”维修新标准
运维·服务器·性能优化
青火coding1 小时前
SOFAServerless架构的意义
java·运维·中间件·架构·serverless
橘颂TA1 小时前
【Linux 网络】TCP 拥塞控制与异常处理:从原理到实践的深度剖析
linux·运维·网络·tcp/ip·算法·职场和发展·结构与算法
啊湘1 小时前
服务器维护------日志大小控制
运维·服务器·日志大小
thulium_1 小时前
Redis Cluster + Docker + --net=host在 WSL2 下是一个“看起来能跑,实际上必失败”的组合
redis·docker
qq_366086222 小时前
SQL Server 之 Full-Text Search 全文搜索
运维·服务器·数据库
2401_873587822 小时前
Linux——应用层协议定制
linux·运维·网络协议
大榕树信息科技3 小时前
动环监控如何提升数据中心的运维效率和安全性?
运维·网络·物联网·机房管理系统·动环监控系统