? ? ? ? containerd 是一個行業標準的容器運行時,專注于簡單、健壯的容器執行。它是從 Docker 中分離出來的項目,旨在作為一個底層的運行時接口,供更高層次的容器管理層使用。
containerd 負責鏡像傳輸、存儲、容器執行、網絡配置等工作。它向上為 Docker 等高級容器管理層提供 API 接口,向下則直接調用操作系統內核特性或通過 runC 來運行容器。
containerd.sock 是由 containerd 自動創建的,前提是 containerd 已經被正確安裝、配置并啟動。
? ? ?Docker 使用 containerd 作為其容器運行時的一部分。當你通過 Docker CLI 或 API 發出命令時,這些命令會首先到達 Docker 守護進程(docker daemon),然后 Docker 守護進程可能會通過 gRPC 接口將具體的容器運行任務委派給 containerd 來執行。?
1.離線部署docker
詳見離線安裝 docker 和 docker-compose
2.配置文件
sudo mkdir -p /etc/containerd/
containerd config default | sudo tee /etc/containerd/config.toml
3.系統服務
下載:
https://raw.githubusercontent.com/containerd/containerd/main/containerd.service
cp containerd.service??/etc/systemd/system/
chmod +x /etc/systemd/system/containerd.service
# Copyright The containerd Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target dbus.service[Service]
#uncomment to enable the experimental sbservice (sandboxed) version of containerd/cri integration
#Environment="ENABLE_CRI_SANDBOXES=sandboxed"
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerdType=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999[Install]
WantedBy=multi-user.target
Description:
提供了對該服務單元的簡短描述。
在這個例子中,描述為 "containerd container runtime",表示這是一個用于容器運行的 containerd 服務。
Documentation:
提供了指向官方文檔的鏈接,幫助用戶了解更多信息。
在這個例子中,鏈接指向 https://containerd.io。
After:
指定了在啟動此服務之前需要啟動的其他服務或目標(target)。
在這個例子中,containerd 將在網絡 (network.target)、本地文件系統 (local-fs.target) 和 D-Bus (dbus.service) 啟動之后再啟動。
ExecStartPre:
在啟動主進程之前執行的命令。
-/sbin/modprobe overlay 表示嘗試加載內核模塊 overlay,前面的 - 表示即使該命令失敗也不會阻止服務啟動。
ExecStart:
指定要啟動的主進程命令。
/usr/bin/containerd 是 containerd 守護進程的可執行文件路徑。
Type:
定義了服務的啟動類型。
notify 表示 containerd 將通過 sd_notify(3) 協議通知 systemd 其啟動狀態。
Delegate:
允許 containerd 管理自己的 cgroup 層次結構。
yes 表示啟用這種行為。
KillMode:
定義了當停止服務時應終止哪些進程。
process 表示僅終止主進程。
Restart:
定義了服務失敗時是否以及如何重啟。
always 表示無論退出代碼是什么,都會重啟服務。
RestartSec:
定義了在服務失敗后等待多久進行重啟。
5 表示等待 5 秒后再重啟。
LimitNPROC, LimitCORE, LimitNOFILE:
設置了對進程數、核心轉儲大小和打開文件描述符數量的限制。
infinity 表示沒有限制。
TasksMax:
設置了服務可以創建的最大任務數。
infinity 表示沒有限制,但需注意只有 systemd 226 及以上版本支持此設置。
OOMScoreAdjust:
調整服務的 OOM(Out of Memory)分數。
-999 表示盡量避免在內存不足時殺死該服務。
WantedBy:
指定了在哪些目標(target)下該服務單元會被自動啟動。
在這個例子中,multi-user.target 是一個常見的 systemd target,代表多用戶模式(即非圖形界面的完整系統啟動狀態)。這意味著當你運行 systemctl enable containerd.service 時,containerd 服務將在系統進入多用戶模式時自動啟動。
4.啟動服務
sudo systemctl daemon-reload
sudo systemctl start containerd
???????5.設置開機啟動
sudo systemctl enable containerd
???????6.服務狀態
sudo systemctl status containerd