Containerd安装 1 2 3 4 5 rpm -qa |grep libseccomp yum install wget -y wget http://mirror.centos.org/centos/7/os/x86_64/Packages/libseccomp-2.3.1-4.el7.x86_64.rpm yum install libseccomp-2.3.1-4.el7.x86_64.rpm -y
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 wget https://github.com/containerd/containerd/releases/download/v1.5.5/cri-containerd-cni-1.5.5-linux-amd64.tar.gz tar -C / -xzf cri-containerd-cni-1.5.5-linux-amd64.tar.gz echo 'export PATH=$PATH:/usr/local/bin:/usr/local/sbin' >> ~/.bashrc source ~/.bashrcmkdir -p /etc/containerd containerd config default > /etc/containerd/config.toml cat /etc/systemd/system/containerd.service systemctl enable containerd --now ctr version ctr plugin ls [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://bqr1dr1n.mirror.aliyuncs.com" ] [plugins."io.containerd.grpc.v1.cri" .registry.mirrors."k8s.gcr.io" ] endpoint = ["https://registry.aliyuncs.com/k8sxio" ]
Containerd使用 镜像相关 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 ctr image pull docker.io/library/nginx:alpine ctr image push ctr image ls ctr image check ctr image tag docker.io/library/nginx:alpine harbor.k8s.local/course/nginx:alpine ctr image rm harbor.k8s.local/course/nginx:alpine ctr image mount docker.io/library/nginx:alpine /mnt ctr image unmount /mnt ctr image export --all-platforms nginx.tar.gz docker.io/library/nginx:alpine ctr image import nginx.tar.gz ctr i pull --all-platforms docker.io/library/nginx:alpine ctr i export --all-platforms nginx.tar.gz docker.io/library/nginx:alpine ctr i rm docker.io/library/nginx:alpine ctr i import nginx.tar.gz
容器相关 1 2 3 4 5 6 7 8 9 10 11 12 ctr container create docker.io/library/nginx:alpine nginx ctr container ls ctr container info nginx ctr container rm nginx ctr container ls
任务相关 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 ctr container create docker.io/library/nginx:alpine nginx ctr task start -d nginx ctr task ls ctr task metrics nginx ctr task ps nginx ctr task exex --exec-id 0 -t nginx sh ctr task pause nginx ctr task ls ctr task resume nginx ctr task ls ctr task kill nginx ctr task ls ctr task rm nginx ctr task ls
命名空间 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ctr ns ls ctr ns creat test ctr ns rm test ctr -n test image ls ctr -n moby container ls
Containerd高级工具nerdctl 安装 1 2 3 4 5 6 7 8 9 10 wget https://github.com/containerd/nerdctl/releases/download/v0.12.1/nerdctl-0.12.1-linux-amd64.tar.gz mkdir -p /usr/local /containerd/bin/ && tar -zxvf nerdctl-0.12.1-linux-amd64.tar.gz nerdctl && mv nerdctl /usr/local /containerd/bin/ ln -s /usr/local /containerd/bin/nerdctl /usr/local /bin/nerdctl nerdctl version
使用命令 容器相关 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 nerdctl run -d -p 80:80 --name=nginx --restart=always nginx:alpine nerdctl exec -it nginx /bin/sh nerdctl ps nerdctl inspect nginx nerdctl logs -f nginx nerdctl stop nginx nerdctl rm nginx
镜像相关 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 nerdctl images nerdctl pull docker.io/library/busybox:latest nerdctl login --username xxx --password xxx nerdctl logout nerdctl push nerdctl tag nginx:alpine harbor.k8s.local/course/nginx:alpine nerdctl save -o busybox.tar.gz busybox:lastest nerdctl rmi busybox nerdctl load -i busybox.tar.gz
构建镜像 安装 buildctl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 nerdctl build 需要依赖 buildkit 工具 buildkit 项目也是 Docker 公司开源的一个构建工具包,支持 OCI 标准的镜像构建。它主要包含以下部分 服务端 buildkitd:当前支持 runc 和 containerd 作为 worker,默认是 runc,我们这里使用 containerd 客户端 buildctl:负责解析 Dockerfile,并向服务端 buildkitd 发出构建请求 buildkit 是典型的 C/S 架构,客户端和服务端是可以不在一台服务器上,而 nerdctl 在构建镜像的时候也作为 buildkitd 的客户端,所以需要我们安装并运行 buildkitd wget https://github.com/moby/buildkit/releases/download/v0.9.1/buildkit-v0.9.1.linux-amd64.tar.gz tar -zxvf buildkit-v0.9.1.linux-amd64.tar.gz -C /usr/local /containerd/ ln -s /usr/local /containerd/bin/buildkitd /usr/local /bin/buildkitd ln -s /usr/local /containerd/bin/buildctl /usr/local /bin/buildctl cat /etc/systemd/system/buildkit.service [Unit] Description=BuildKit Documentation=https://github.com/moby/buildkit [Service] ExecStart=/usr/local /bin/buildkitd --oci-worker=false --containerd-worker=true [Install] WantedBy=multi-user.target systemctl daemon-reload systemctl enable buildkit --now systemctl status buildkit
构建 1 2 3 4 5 6 7 8 9 10 11 12 13 14 cat Dockerfile FROM nginx RUN echo 'Hello Nerdctl From Containerd' > /usr/share/nginx/html/index.html nerdctl build -t nginx:nerdctl -f Dockerfile . nerdctl images nerdctl run -d -p 80:80 --name=nginx --restart=always nginx:nerdctl crul 127.0.0.1
文档整理:https://www.qikqiak.com/k3s/