0%

containerd启动并使用

离线安装

如果是离线安装的docker,可以自己准备一份containerd.service用于管理containerd启停。

# 生成或检查默认配置文件
containerd config default > /etc/containerd/config.toml

# 创建服务文件
sudo vim /etc/systemd/system/containerd.service
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target

[Service]
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=1048576
# 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
# 重新加载 Systemd 配置
sudo systemctl daemon-reload
# 启动 containerd
sudo systemctl start containerd
# 设置为开机自启动:
sudo systemctl enable containerd

nerdctl

containerd自带的ctl命令与docker命令不一样,使用不习惯的用户可以考虑安装nerdctl。这个工具命令风格和docker一致。

# 下载最新版本
wget https://github.com/containerd/nerdctl/releases/download/v2.0.1/nerdctl-2.0.1-linux-amd64.tar.gz
# 安装
sudo tar -C /usr/local/bin -xzf nerdctl-2.0.1-linux-amd64.tar.gz
# 测试
nerdctl version

安装CNI插件

下载页下载最新版本

wget https://github.com/containernetworking/plugins/releases/download/v1.6.1/cni-plugins-linux-amd64-v1.6.1.tgz
# 解压到 /opt/cni/bin 目录
sudo mkdir -p /opt/cni/bin
sudo tar -xzf cni-plugins-linux-amd64-v1.6.1.tgz -C /opt/cni/bin
# 验证插件是否安装成功
ls /opt/cni/bin

检查containerd配置,确保CNI配置正确

[plugins."io.containerd.grpc.v1.cri".cni]
  bin_dir = "/opt/cni/bin"
  conf_dir = "/etc/cni/net.d"

然后重启sudo systemctl restart containerd.

使用nerdctl network create bridge创建一个新的默认 bridge 网络.

# 检查网络是否创建成功
nerdctl network ls