这个过程主要分为两大部分:设置 Docker 的官方软件仓库 和 执行安装。
第一步:设置 Docker 的软件仓库
由于 containerd.io
包含在 Docker 的官方仓库中,您需要先让您的系统信任并能够从该仓库下载软件。
-
添加 Docker 的 GPG 密钥:
这确保了您下载的软件包是官方发布且未经篡改的。# 创建用于存放密钥的目录 sudo install -m 0755 -d /etc/apt/keyrings# 下载并添加 Docker 的 GPG 密钥 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg sudo chmod a+r /etc/apt/keyrings/docker.gpg
-
将 Docker 仓库添加到 APT 源中:
这个命令会创建一个新的软件源列表文件,告诉apt
工具可以去哪里寻找 Docker 相关的软件包。echo \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
第二步:安装 containerd
仓库设置好之后,安装就非常简单了。
-
更新软件包列表:
刷新您的本地软件包索引,让系统知道 Docker 仓库中有哪些可用的新软件包。sudo apt update
-
安装 containerd. Io:
从刚刚配置好的仓库中安装containerd.io
。sudo apt install -y containerd.io
第三步:验证安装
安装完成后,您可以检查 containerd
的版本来确认它是否已成功安装。
containerd --version
如果命令返回版本号(例如 containerd github.com/containerd/containerd/v2 v2.1.4 75cb2b7193e4e490e9fbdc236c0e811ccaba3376
),则说明安装成功。
注:低版本的containerd 可能不支持镜像校验插件,如果不是2.1.4 版本,手动升级一下。
第四步:修改配置文件
修改 containerd 配置文件
生成默认配置文件:/etc/containerd/config.toml
sudo mkdir -p /etc/containerd
# 把默认配置写入到config.toml文件中
sudo /usr/local/bin/containerd config default | sudo tee /etc/containerd/config.toml > /dev/null
修改服务配置文件
生成服务配置文件:/etc/systemd/system/containerd.Service
sudo tee /etc/systemd/system/containerd.service > /dev/null << 'EOF'
# 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
#
# https://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[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerdType=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.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this option.
TasksMax=infinity
OOMScoreAdjust=-999[Install]
WantedBy=multi-user.target
EOF
重新加载systemd配置并启动服务:
sudo systemctl daemon-reload
sudo systemctl start containerd
检查服务状态:
sudo systemctl status containerd
第五步:安装命令行工具(可选)
Crictl:会触发验证脚本
Containerd 可以搭配一个命令行工具使用,这里使用 crictl
# 获取源码
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.29.0/crictl-v1.29.0-linux-arm64.tar.gz# 解压
sudo tar -C /usr/local/bin -xzf crictl-v1.29.0-linux-arm64.tar.gz# 校验是否安装成功
sudo crictl --version
Nerdctl:不会触发验证脚本
[[nerdctl介绍]]
# 前往 https://github.com/containerd/nerdctl/releases 查看最新版本
VERSION="2.1.3" # 示例版本
ARCH="arm64" #选择自己计算机架构的版本
wget "https://github.com/containerd/nerdctl/releases/download/v${VERSION}/nerdctl-${VERSION}-linux-${ARCH}.tar.gz"
sudo tar Cxzvvf /usr/local/ "nerdctl-${VERSION}-linux-${ARCH}.tar.gz"# 验证安装
nerdctl --version
查看计算机架构:
uname -m
- 如果输出是
x86_64
,那么你的机器是 AMD 64 架构, ARCH 填amd64
- 如果输出是
aarch64
或arm64
,那么你的机器是 ARM 64 架构,ARCH 填arm64
安装后仍然找不到 nerdctl 命令,可能是因为安装到了错误的目录
# 在 /usr/local 目录下查找名为 nerdctl 的文件
sudo find /usr/local -name nerdctl
# 如果不在/usr/local/bin/ 目录,移动过去
sudo mv /usr/local/nerdctl /usr/local/bin/