docker離線安裝並配置docker.service為服務自啟動


背景介紹

項目開發過程中,客戶環境大多是全內網環境,無法連接互聯網。這樣docker就不能yum在線聯網安裝,所需要的鏡像也不能在線pull下載。
這時就需要進行離線安裝docker及鏡像。

下載docker安裝文件

docker 離線包

開始安裝

解壓:
tar -xvf docker-19.03.6.tar

cp 將解壓出來的docker文件內容移動到 /usr/bin/ 目錄下 :
cp docker/* /usr/bin/

docker 注冊為服務

創建配置文件

vim /etc/systemd/system/docker.service

內容參考: 補充配置文件 docker.service

重啟 docker 服務

chmod +x /etc/systemd/system/docker.service #添加文件權限
systemctl daemon-reload #重載unit配置文件
systemctl start docker #啟動Docker
systemctl enable docker.service

注意:如果你的服務已經啟動,一定要先停止,否則啟動失敗,此時 systemctl start docker 無法停止,需要手動 kill掉

驗證是否注冊為服務

輸入命令,觀察效果
[root@host-10-227-50-187 system]# systemctl start docker
[root@host-10-227-50-187 system]# systemctl stop docker
[root@host-10-227-50-187 system]# docker ps

補充配置文件 docker.service

[root@host-10-227-50-187 system]# vim  /etc/systemd/system/docker.service 

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
# BindsTo=containerd.service
# After=network-online.target firewalld.service containerd.service
After=network-online.target firewalld.service
Wants=network-online.target
# Requires=docker.socket

[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 -H fd:// --containerd=/run/containerd/containerd.sock
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# 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

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
# TasksMax=infinity

# 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

[Install]
WantedBy=multi-user.target

~                                                                                                                                                                                                                
~                                                                                                                                                                                                                
~                                                                                                                                                                                                                
~                                                                                                                                                                                                                
~                                                                                                                                                                                                                
"/etc/systemd/system/docker.service" 50L, 1767C                                                                                                                                                50,0-1       全部
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
# BindsTo=containerd.service
# After=network-online.target firewalld.service containerd.service
After=network-online.target firewalld.service
Wants=network-online.target
# Requires=docker.socket

[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 -H fd:// --containerd=/run/containerd/containerd.sock
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# 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

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
# TasksMax=infinity

# 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

[Install]
WantedBy=multi-user.target


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM