1. 下載docker的離線安裝包
下載編譯好的離線安裝包直接安裝,但是需要選好對應平臺,如x86、amd、arm要選擇正確。使用uname -m查看自己的平臺
建議選擇阿里的速度會快一些
2. 解壓安裝
如果之前已經安裝過其他的版本需要先卸載掉
#解壓縮
tar zxvf docker-18.09.4.tgz
#將二進制文件拷到/usr/bin下
cp docker/* /usr/bin/
3. 配置docker.service
創建文件/usr/lib/systemd/system/docker.service添加內容如下,該文件在使用systemctl enable設置開啓啓動時會用到。
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
#BindsTo=containerd.service. — 無需containerd。
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 -H unix://
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 supports 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
4. 添加docker鏡像加速器
進入阿里雲容器鏡像服務:https://cr.console.aliyun.com/cn-hangzhou/instances/repositories
選擇“容器鏡像加速器”按照提示:
通過修改daemon配置文件/etc/docker/daemon.json來使用加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://r4utyp3e.mirror.aliyuncs.com"]
}
EOF
5. 運行docker、設置開機啓動
#加載新的unit 配置文件
systemctl daemon-reload
#啓動docker
systemctl start docker
#設置開機啓動
systemctl enable docker
6. 驗證是否安裝成功
[root@raspberrypi ~]$ docker version
Client: Docker Engine - Community
Version: 18.09.0
API version: 1.39
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov 7 00:48:53 2018
OS/Arch: linux/arm
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.0
API version: 1.39 (minimum version 1.12)
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov 7 01:24:34 2018
OS/Arch: linux/arm
Experimental: false
7. docker版本升級後client和server版本不一至
如果二進制安裝後需要進行使用apt等工具進行版本升級時升級完可能出現docker的client端和server端不一致的情況
如:
#使用apt docker升級到19.03.8
apt install docker-ce
#docker version查詢升級後的版本發現clent版本還是18.09.0
[root@raspberrypi /home/sunkai]$ docker version
Client: Docker Engine - Community
Version: 18.09.0
API version: 1.39
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov 7 00:48:53 2018
OS/Arch: linux/arm
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.8
API version: 1.40 (minimum version 1.12)
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:29:22 2020
OS/Arch: linux/arm
Experimental: false
containerd:
Version: v1.1.2
GitCommit: 468a545b9edcd5932818eb9de8e72413e616e86e
runc:
Version: 1.0.0-rc5+dev
GitCommit: 69663f0bd4b60df09991c08812a60108003fa340
docker-init:
Version: 0.18.0
GitCommit: fec3683
卸載重裝還是不行,卸載後發現/usr/bin/docker依舊存在懷疑卸載時值把server卸載了。目前沒找到好的解決方案,只能去官網把docker client端對應的版本下載下來替換掉。
參考: Docker 18.09離線安裝
可能遇到的問題:
Docker安裝完啓動時提示Failed to start docker.service: Unit docker.service is masked.
解決辦法: https://blog.csdn.net/u011403655/article/details/50524071