考慮到很多生產環境是內網,不允許外網存取的。恰好我司正是這種場景,寫一篇二進位制方式安裝Docker的教學,用來幫助實施同事解決容器部署的第一個難關。
本文將以二進位制安裝方式,在CentOS7.9上安裝Docker 19.03.9,具有一定的通用性,其他版本也可參考本文。讓我們開始吧。
https://download.docker.com/linux/static/stable/ ,根據架構選擇目錄,本文以x86_64舉例
將壓縮包上傳到伺服器
在伺服器上,解壓壓縮包
tar -xvf docker-19.03.0-ce.tgz
將解壓出的docker/bin目錄下的可執行檔案複製到/usr/bin
cp docker/* /usr/bin/
將docker註冊為 Systemd 的 service
cat > /etc/systemd/system/docker.service <<EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
EOF
為 docker.service新增可執行許可權
chmod +x /etc/systemd/system/docker.service
設定docker儲存目錄到大硬碟目錄、設定私有映象倉庫地址(可選,注意替換目錄位置與私有映象倉庫URL)
mkdir /etc/docker
mkdir /data1/docker #/data1是大硬碟目錄
# 主要關注data-root的值是大硬碟目錄存放docker相關檔案的目錄
# insecure-registries後邊的值是私有映象倉庫地址,多個私有映象倉庫地址設定格式為["倉庫1","倉庫2"]
# exec-opts部分針對於部署k8s做的預設定,可以減少容器紀錄檔儲存大小及配合kubelet使用systemd
cat > /etc/docker/daemon.json <<EOF
{
"insecure-registries":["10.2.41.191:5000"],
"data-root":"/data1/docker",
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "20m"
},
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
]
}
EOF
啟動docker並設定開機自啟
systemctl daemon-reload
systemctl enable --now docker.service
驗證安裝結果
systemctl status docker #檢視docker服務狀態
docker -v #檢視docker版本
本文同步釋出在本人CSDN https://blog.csdn.net/u012586326 與 部落格園 https://www.cnblogs.com/hellxz/ ,禁止爬蟲與未經允許的洗稿。