1. 安装 containerd
yum -y install containerd
systemctl status containerd
链接
修改镜像仓库地址
vi /etc/containerd/config.toml
#-----------------------------
[plugins."io.containerd.grpc.v1.cri".registry]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
endpoint = ["https://4iv7219l.mirror.aliyuncs.com", "https://registry-1.docker.io"]
......
启动可能会报错,参考 journalctl -xeu containerd 删除重复配置
链接
systemctl daemon-reload && systemctl restart containerd
2. containerd 基本使用
查看命名空间
ctr namespace ls
拉取镜像
ctr images pull docker.io/library/alpine:latest
查看镜像
ctr images ls
ctr -n default image ls
运行容器
ctr run -d --net-host docker.io/library/alpine:latest test-container sh
查看容器
ctr container ls
ctr -n default container ls
ctr -n default task ls
镜像打 tag
ctr images tag docker.io/library/redis:alpine harbor.junengcloud.com/tmp/redis:alpine
链接1
链接2
3. crictl 安装使用
3.1 crictl 安装
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.24.0/crictl-v1.24.0-linux-amd64.tar.gz
tar -zxvf crictl-v1.24.0-linux-amd64.tar.gz -C /usr/local/bin
cat > /etc/crictl.yaml <<EOF
runtime-endpoint: unix:///var/run/containerd/containerd.sock
image-endpoint: unix:///var/run/containerd/containerd.sock
timeout: 10
debug: false
pull-image-on-create: false
EOF
systemctl daemon-reload
如果有如下报错:链接
This could be that you are using an incorrect containerd configuration (maybe from a Docker install). You will need to update your containerd configuration to the containerd instance that you are running. One way of doing this is as follows:
mv /etc/containerd/config.toml /etc/containerd/config.bak
containerd config default > /etc/containerd/config.toml
systemctl daemon-reload
sytemctl restart containerd
3.2 crictl 使用
crictl ps
crictl images ps
crictl pull nginx:1.18.0
crictl pods --name etcd
crictl exec -it 1f73f2d81bf98 ls
链接
4. nerdctl 安装使用
4.1 nerdctl 安装
根据自己的 containerd 版本安装合适的 nerdctl
[21:29:54 root@c7-3~]#containerd --version
containerd containerd.io 1.6.8 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
wget https://github.com/containerd/nerdctl/releases/download/v0.22.2/nerdctl-0.22.2-linux-amd64.tar.gz
tar -zxvf nerdctl-0.22.2-linux-amd64.tar.gz
mv nerdctl /usr/local/bin
安装 CNI 插件文章来源:https://www.toymoban.com/news/detail-467673.html
wget https://github.com/containernetworking/plugins/releases/download/v1.1.1/cni-plugins-linux-amd64-v1.1.1.tgz
mkdir -p /opt/cni/bin
tar zxvf cni-plugins-linux-amd64-v1.1.1.tgz -C /opt/cni/bin/
4.2 nerdctl 使用
nerdctl pull nginx:1.18.0
nerdctl ps -a
nerdctl images -a
nerdctl run -d -p 8080:80 --name=nginx --restart=always nginx:1.18.0
nerdctl exec -it 70d014105fed bash
nerdctl network ls
nerdctl network inspect bridge
nerdctl rm -f 600f493049b9
5. 总结
文章来源地址https://www.toymoban.com/news/detail-467673.html
到了这里,关于Containerd 安装使用与高级命令行工具 crictl、nerdctl的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!