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