天天看點

Linux伺服器離線安裝Docker

作者:小舟雜筆

環境說明

CentOS等Linux作業系統基本是一樣的,根據CPU架構[ARM、AMD|X86]選擇對應的tgz包即可

  • 作業系統:統信UOS20
  • CPU架構:ARM

安裝步驟

本文章示例下載下傳的tgz包為:docker-23.0.1.tgz

  • 步驟一:

    選擇CPU為ARM架構的tgz包進行下載下傳:https://download.docker.com/linux/static/stable/aarch64

  • 步驟二:

    解壓tgz包(完成後是一個docker檔案夾):tar -zxvf docker-23.0.1.tgz

  • 步驟三:

    将docker目錄拷貝到/user/bin下(會提示是否覆寫/usr/bin/runc,覆寫即可):cp docker/* /usr/bin/

  • 步驟四:

    系統注冊docker.service服務,對檔案進行編輯:vi /etc/systemd/system/docker.service

    添加以下内容:

[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 --selinux-enabled=false --insecure-registry=127.0.0.1
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           
  • 步驟五:

    docker.service檔案添加可執行權限:chmod +x /etc/systemd/system/docker.service

  • 步驟六:

    重新加載配置檔案:systemctl daemon-reload

  • 步驟七:

    啟動docker服務:systemctl start docker

  • 步驟八:

    檢驗docker服務啟動狀态:systemctl status docker

    列印日志如下所示:

[root@zhxf-xfclznzhdd-yy docker]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/etc/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2023-05-10 15:54:56 CST; 1min 7s ago
     Docs: https://docs.docker.com
 Main PID: 1570793 (dockerd)
    Tasks: 28 (limit: 92329)
   Memory: 40.6M
   CGroup: /system.slice/docker.service
           ├─1570793 /usr/bin/dockerd --selinux-enabled=false --insecure-registry=127.0.0.1
           └─1570806 containerd --config /var/run/docker/containerd/containerd.toml --log-level info

5月 10 15:54:51 zhxf-xfclznzhdd-yy dockerd[1570793]: time="2023-05-10T15:54:51.492829560+08:00" level=info msg="[core] [Channel #7] Channel Connectivity change to READY" module=grpc
5月 10 15:54:51 zhxf-xfclznzhdd-yy dockerd[1570793]: time="2023-05-10T15:54:51.823845880+08:00" level=info msg="Loading containers: start."
5月 10 15:54:55 zhxf-xfclznzhdd-yy dockerd[1570793]: time="2023-05-10T15:54:55.707291010+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be>
5月 10 15:54:55 zhxf-xfclznzhdd-yy dockerd[1570793]: time="2023-05-10T15:54:55.894126710+08:00" level=info msg="Firewalld: interface docker0 already part of docker zone, returning"
5月 10 15:54:56 zhxf-xfclznzhdd-yy dockerd[1570793]: time="2023-05-10T15:54:56.244892100+08:00" level=info msg="Loading containers: done."
5月 10 15:54:56 zhxf-xfclznzhdd-yy dockerd[1570793]: time="2023-05-10T15:54:56.331908950+08:00" level=info msg="Docker daemon" commit=bc3805a graphdriver=overlay2 version=23.0.1
5月 10 15:54:56 zhxf-xfclznzhdd-yy dockerd[1570793]: time="2023-05-10T15:54:56.332074230+08:00" level=info msg="Daemon has completed initialization"
5月 10 15:54:56 zhxf-xfclznzhdd-yy dockerd[1570793]: time="2023-05-10T15:54:56.903699400+08:00" level=info msg="[core] [Server #10] Server created" module=grpc
5月 10 15:54:56 zhxf-xfclznzhdd-yy systemd[1]: Started Docker Application Container Engine.
5月 10 15:54:56 zhxf-xfclznzhdd-yy dockerd[1570793]: time="2023-05-10T15:54:56.912701240+08:00" level=info msg="API listen on /var/run/docker.sock"
           

Active: active (running)

  • 步驟九:

    檢視docker資訊,確定安裝的就是自己安裝的版本:docker info

  • 步驟十:

    設定伺服器開機自啟動:systemctl enable docker.service