Ubuntu安装containerd:
更新镜像仓库并安装依赖包:
root@ubuntu2204:~# apt update
root@ubuntu2204:~# sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common
导入docker的公钥:
root@ubuntu2204:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
添加镜像源:
root@ubuntu2204:~#echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker- ce/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
更新镜像仓库:
root@ubuntu2204:~# apt update
验证containerd版本:
root@ubuntu2204:~# apt-cache madison containerd.io
containerd.io | 1.6.8-1 | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu jammy/stable amd64 Packages
containerd.io | 1.6.7-1 | https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu jammy/stable amd64 Packages
安装containerd:
root@ubuntu2204:~# apt install containerd.io=1.6.8-1
root@ubuntu2204:~# containerd --version
containerd containerd.io 1.6.8 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
centos安装containerd:
~]# yum install -y yum-utils device-mapper-persistent-data lvm2
~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
~]# sudo sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo
~]# yum list containerd.io --showduplicates | sort –r
~]# yum install containerd.io-1.6.8
containerd配置文件:
默认配置参数:
~# containerd config default
自定义配置:
~]# containerd config default > /etc/containerd/config.toml
61 sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.7”
153 [plugins."io.containerd.grpc.v1.cri".registry.mirrors]
154 [plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
155 endpoint = ["https://xxx.mirror.aliyuncs.com"]
~]# systemctl restart containerd && systemctl enable containerd
更新runc:
# wget https://github.com/opencontainers/runc/releases/download/v1.1.4/runc.amd64
# cp runc.amd64 /usr/bin/runc
# chmod a+x /usr/bin/runc
# runc -v
runc version 1.1.4
客户端使用:
containerd相比docker多了一个命名空间的逻辑概念,ctr命令默认是在default命名空间里,而在使用nerdctl命令的时候,却是在k8s.io命名空间里,所以
不指定namespace会发现看到的镜像、容器等内容不一样。
ctr:(不好用,一般不用)
~]# ctr images pull docker.io/library/nginx:1.20.2
~]# ctr -n k8s.io images ls
~]# ctr images ls
运行容器并使用宿主机网络:
~]# ctr run -t --net-host docker.io/library/nginx:1.20.2 test-container1
nerdctl-是一个兼容docker的containerd的客户端,https://github.com/containerd/nerdctl
~]# wget https://github.com/containerd/nerdctl/releases/download/v0.23.0/nerdctl-0.23.0-linux-amd64.tar.gz
~]# tar xvf nerdctl-0.23.0-linux-amd64.tar.gz -C /usr/bin/
cni:
~]# wget https://github.com/containernetworking/plugins/releases/download/v1.1.1/cni-plugins-linux-amd64-v1.1.1.tgz
~]# mkdir /opt/cni/bin -pv
# tar xvf cni-plugins-linux-amd64-v1.1.1.tgz -C /opt/cni/bin/
创建容器并指定端口:
~]# nerdctl run -d -p 80:80 --name=nginx-web1 --restart=always nginx:1.22.0-alpine
~]# nerdctl ps
~]# nerdctl exec -it 858730bb0492 sh
~]# nerdctl run -d -p 8080:8080 --name=tomcat-web1 --restart=always tomcat:7.0.88-alpine