简介:Containerd是一个开源的容器运行时工具,用于管理和运行容器。它为容器提供了高效,安全的执行环境,支持各种容器格式和镜像,极简化的容器生命周期管理,使得构建和部署应用程序更加方便和可靠。
以下是官方的安装方式,版本为containerd-1.7.2,详细可见官网:https://github.com/containerd/containerd/blob/main/docs/getting-started.md
下载安装包:
# containerd软件包
wget https://github.com/containerd/containerd/releases/download/v1.7.2/containerd-1.7.2-linux-amd64.tar.gz
# runc软件包
wget https://github.com/opencontainers/runc/releases/download/v1.1.7/runc.amd64
# cni软件包
wget https://github.com/containernetworking/plugins/releases/download/v1.3.0/cni-plugins-linux-amd64-v1.3.0.tgz
注:containerd默认不会自带runc(真正创建容器的程序),所以需要安装runc程序,以及cni网络插件(容器之间网络通信所需)。
解压缩,安装
# containerd安装
tar -zxvf containerd-1.6.2-linux-amd64.tar.gz -C /usr/local
# runc安装
install -m 755 runc.amd64 /usr/local/sbin/runc
# cni安装
mkdir -p /opt/cni/bin
tar -zxvf /opt/cni/bin cni-plugins-linux-amd64-v1.1.1.tgz
配置Containerd
# 生成Containerd配置文件
containerd config default > /etc/containerd/config.toml
# 2条配置修改:
# 65行:sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.8" 【修改pause容器镜像为国内】
# 137行:SystemdCgroup = true 【让Runc使用system cgroup驱动,对容器进行资源划分,隔离。】
# wq保存退出
配置Systemd管理Containerd
# 下载Containerd官方提供的Service文件:https://raw.githubusercontent.com/containerd/containerd/main/containerd.service
# 将内容完整的复制到该路径下:
vim /usr/lib/systemd/system/containerd.service
启动Containerd
# 启动
systemctl start containerd
systemctl status containerd
● containerd.service - containerd container runtime
Loaded: loaded (/usr/lib/systemd/system/containerd.service; enabled; vendor preset: disabled)
Active: active (running) since 二 2023-06-13 18:55:26 CST; 5h 4min ago
Docs: https://containerd.io
Process: 17524 ExecStartPre=/sbin/modprobe overlay (code=exited, status=0/SUCCESS)
Main PID: 17526 (containerd)
Tasks: 9
Memory: 20.8M
CGroup: /system.slice/containerd.service
└─17526 /usr/local/bin/containerd
# 拉取镜像
ctr images pull registry.cn-hangzhou.aliyuncs.com/week123456/nginx:latest
结语
Containerd,安装起来方便快捷,本身十分轻量,通过ctr客户端命令进行操作使用,且所有的容器镜像都可以使用运行,是目前推崇使用的容器管理工具。