CentOS8安装Docker,如果我们不限制版本,直接使用官方最简安装,会报错:

[root@localhost ~]# curl -sSL https://get.docker.com | sh
# Executing docker install script, commit: f45d7c11389849ff46a6b4d94e0dd1ffebca32c1
+ sh -c 'yum install -y -q yum-utils'
+ sh -c 'yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo'
Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
+ '[' stable '!=' stable ']'
+ sh -c 'yum makecache'
CentOS-8 - AppStream                                                                                                                                  1.5 kB/s | 4.3 kB     00:02    
CentOS-8 - Base                                                                                                                                       1.4 kB/s | 3.8 kB     00:02    
CentOS-8 - Extras                                                                                                                                     599  B/s | 1.5 kB     00:02    
Docker CE Stable - x86_64                                                                                                                             2.4 kB/s | 3.5 kB     00:01    
Extra Packages for Enterprise Linux 8 - x86_64                                                                                                        4.2 kB/s | 7.2 kB     00:01    
Metadata cache created.
+ '[' -n '' ']'
+ sh -c 'yum install -y -q docker-ce'
Error: 
 Problem: package docker-ce-3:19.03.3-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
  - cannot install the best candidate for the job
  - package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.el7.x86_64 is excluded
  - package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.6-3.3.el7.x86_64 is excluded

报错信息显示需要安装containerd.io,所以正确的安装方式相比较CentOS7,会增加一个步骤。

官方慢速安装

# install containerd.io
[root@localhost ~]# dnf install -y https://download.docker.com/linux/centos/7/x86_64/nightly/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm

# install docker-ce
[root@localhost ~]# curl -sSL https://get.docker.com | sh

国内加速安装

# install containerd.io from aliyun mirror
[root@localhost ~]# dnf install -y https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/nightly/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm

# install docker-ce from daocloud mirror
[root@localhost ~]# curl -sSL https://get.daocloud.io/docker | sh

启动Docker

[root@localhost ~]# systemctl enable --now docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
[root@localhost ~]# docker version
Client: Docker Engine - Community
 Version:           19.03.3
 API version:       1.40
 Go version:        go1.12.10
 Git commit:        a872fc2f86
 Built:             Tue Oct  8 00:58:10 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.3
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.10
  Git commit:       a872fc2f86
  Built:            Tue Oct  8 00:56:46 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.6
  GitCommit:        894b81a4b802e4eb2a91d1ce216b8817763c29fb
 runc:
  Version:          1.0.0-rc8
  GitCommit:        425e105d5a03fabd737a126ad93d62a9eeede87f
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

安装Docker-compose

# install docker-compose from daocloud mirror
[root@localhost ~]# curl -L https://get.daocloud.io/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
[root@localhost ~]# chmod +x /usr/local/bin/docker-compose

# makesure version
[root@localhost ~]# docker-compose version
docker-compose version 1.24.1, build 4667896b
docker-py version: 3.7.3
CPython version: 3.6.8
OpenSSL version: OpenSSL 1.1.0j  20 Nov 2018

配置Docker加速

# use daocloud docker registry mirror
[root@localhost ~]# echo '{"registry-mirrors": ["http://f1361db2.m.daocloud.io"]}' >/etc/docker/daemon.json
[root@localhost ~]# systemctl restart docker

# makesure mirror
[root@localhost ~]# docker info
···
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  http://f1361db2.m.daocloud.io/
 Live Restore Enabled: false
Last modification:October 9th, 2019 at 11:24 am