Containerd是一個開源的容器運行時工具,它為容器提供了核心功能。作為一個獨立的項目,Containerd旨在管理容器的核心功能,如鏡像管理、容器生命周期管理、網絡和存儲管理等。它是由Docker項目中的核心組件分離出來的,用于提供一個更加輕量級、獨立且可嵌入的容器運行時環境。Containerd被設計為一個通用的核心容器運行時,因此許多容器平臺和工具都可以構建在其之上,包括Kubernetes、Docker等。Containerd并不是直接面向終端用戶的工具,而是為了提供穩定、可靠的容器基礎設施,讓開發者和其他項目可以基于它構建更高級別的容器化解決方案。
Docker和Containerd之間有一種父子關系。Containerd實際上是從Docker項目中拆分出來的,是Docker引擎中的核心組件之一。具體來說,Docker Engine在其架構中使用了一種插件化的方式,而Containerd就是其中一個重要的組件。Docker Engine的架構涵蓋了各種功能模塊,其中包括容器構建、鏡像管理、容器運行時、網絡和存儲管理等。Containerd被用作Docker Engine中負責容器生命周期管理和基本操作的核心組件之一。因此,Docker實際上是建立在Containerd之上的應用層工具。當你使用Docker命令時,它會與Containerd交互以執行諸如創建、運行和管理容器等操作。然而,Containerd本身更加通用和抽象化,可以為其他容器平臺和工具提供底層支持,而不僅限于Docker。總體而言,Docker是一個集成了各種工具和功能的容器平臺,而Containerd是其中一個核心組件,負責提供基本的容器運行時功能。
[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core)
下載地址?https://github.com/containerd/containerd最新版本1.7.10
[root@localhost ~]# wget https://github.com/containerd/containerd/releases/download/v1.7.10/cri-containerd-1.7.10-linux-amd64.tar.gz[root@localhost ~]# tar xf cri-containerd-1.7.10-linux-amd64.tar.gz -C /
[root@localhost ~]# mkdir /etc/containerd[root@localhost ~]# containerd config default > /etc/containerd/config.toml查看配置[root@localhost ~]# cat/etc/containerd/config.toml安裝好containerd 之后,Containerd的配置文件中有如下兩項配置:root = /var/lib/containerdstate = "/run/containerd"root配置的目錄是用來保存持久化數據的目錄,包括content, snapshot, metadata和runtimestate 是用來保存運行時的臨時數據的,包括 sockets、pid、掛載點、運行時狀態以及不需要持久化的插件數據。
[root@localhost ~]# systemctl enable --now containerdCreated symlink from /etc/systemd/system/multi-user.target.wants/containerd.service to /etc/systemd/system/containerd.service.[root@localhost ~]# systemctl start containerd驗證其版本[root@localhost ~]# containerd --versioncontainerd github.com/containerd/containerd v1.7.10 4e1fe7492b9df85914c389d1f15a3ceedbb280ac
默認 Containerd 安裝好就會自帶一個 runc 命令
執行runc命令,如果有版本號返回則為正常[root@localhost ~]# runc -vrunc version 1.1.10commit: v1.1.10-0-g18a0cb0fspec: 1.0.2-devgo: go1.20.10libseccomp: 2.5.4
如果運行runc命令時提示:runc: error while loading shared libraries: ?libseccomp.so.2: cannot open shared object file: No such file or directory,則表明runc沒有找到libseccomp,需要安裝 libseccomp libseccomp安裝
[root@localhost ~]# wget https://github.com/opencontainers/runc/releases/download/v1.1.5/libseccomp-2.5.4.tar.gz[root@localhost ~]# tar xf libseccomp-2.5.4.tar.gz[root@localhost ~]# cd libseccomp-2.5.4/[root@localhost ~]# ./configure[root@localhost ~]# make && make install查找的到 即安裝成功[root@localhost ~]# find / -name "libseccomp.so"/root/libseccomp-2.5.4/src/.libs/libseccomp.so /usr/local/lib/libseccomp.so
做軟鏈
[root@localhost ]# ln -s /usr/local/lib/libseccomp.so /lib64/libseccomp.so.2再次查看[root@localhost ]# runc -vrunc version 1.1.10commit: v1.1.10-0-g18a0cb0fspec: 1.0.2-devgo: go1.20.10libseccomp: 2.5.4
也可以二進制runc安裝?https://github.com/opencontainers/runc最新版本:1.1.10
[root@localhost ~]# wget https://github.com/opencontainers/runc/releases/download/v1.1.10/runc.amd64[root@localhost ~]# chmod +x runc.amd64查找containerd安裝時已安裝的runc所在的位置,然后替換[root@localhost ~]# which runc /usr/local/sbin/runc替換containerd已安裝的runc[root@localhost ~]# mv runc.amd64 /usr/local/sbin/runc執行runc命令,如果有命令幫助則為正常[root@localhost ~]# runc -vrunc version 1.1.10commit: v1.1.10-0-g18a0cb0fspec: 1.0.2-devgo: go1.20.10libseccomp: 2.5.4
在使用 yum 包管理器安裝 Containerd 之前,需要先設置 Containerd 的 YUM 倉庫。以下是大致的步驟:
創建一個名為 /etc/yum.repos.d/containerd.repo 的文件,并將以下內容添加到該文件中:
[containerd]name=containerdbaseurl=https://download.docker.com/linux/centos/7/$basearch/stablegpgcheck=1gpgkey=https://download.docker.com/linux/centos/gpgenabled=1
在設置好倉庫文件后,運行以下命令以更新 YUM 緩存并使其識別新的倉庫信息:
[root@localhost ~]# yum makecache[root@localhost ~]# yum install -y containerd.io
[root@localhost ~]# systemctl enable containerd[root@localhost ~]# systemctl start containerd
[root@localhost ~]# containerd -vcontainerd containerd.io 1.6.25 d8f198a4ed8892c764191ef7b3b06d8a2eeb5c7f[root@localhost ~]# runc -vrunc version 1.1.10commit: v1.1.10-0-g18a0cb0spec: 1.0.2-devgo: go1.20.10libseccomp: 2.3.1
更換 Containerd 后,以往常用的 docker 命令也不再使用,取而代之的分別是 crictl 和 ctr 兩個命令客戶端。一般來說某個主機安裝了 k8s 后,命令行才會有 crictl 命令。而 ctr 是跟 k8s 無關的,主機安裝了 containerd 服務后就可以操作 ctr 命令。
還有一個更高級點的命令 nerdctl ,nerdctl 是用于 containerd 并且 兼容 docker cli 習慣的管理工具,主要適用于剛從 docker 轉到 containerd 的用戶,操作 containerd 的命令行工具 ctr 和 crictl 不怎么好用,所以就有了 nerdctl。
本文鏈接:http://www.www897cc.com/showinfo-26-51843-0.html一文帶你掌握Containerd
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。郵件:2376512515@qq.com
下一篇: 先進存力!曙光存儲位列國內第一陣營