CentOS 8 官方源 containerd.io 版本太低无法安装最新版 Docker-CE。

一、CentOS 8 更换源为阿里云

安装 wget 和 curl 组件:

1
2
yum install wget -y
yum install curl -y

1、备份原文件

1
2
3
4
5
mv /etc/yum.repos.d/CentOS-Linux-BaseOS.repo /etc/yum.repos.d/CentOS-Linux-BaseOS.repo.backup
mv /etc/yum.repos.d/CentOS-Linux-PowerTools.repo /etc/yum.repos.d/CentOS-Linux-PowerTools.repo.backup
mv /etc/yum.repos.d/CentOS-Linux-Extras.repo /etc/yum.repos.d/CentOS-Linux-Extras.repo.backup
mv /etc/yum.repos.d/CentOS-Linux-Plus.repo /etc/yum.repos.d/CentOS-Linux-Plus.repo.backup
mv /etc/yum.repos.d/CentOS-Linux-AppStream.repo /etc/yum.repos.d/CentOS-Linux-AppStream.repo.backup

以上文件都需要重新命名,因为阿里云源里Centos-8.repo包含了上述所有文件,如果按照传统手法只更改CentOS-Linux-BaseOS.repo这个文件 会出现以下错误提示

1
2
3
4
5
6
7
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration

2、修改为阿里云

1
wget -O /etc/yum.repos.d/CentOS-Linux-BaseOS.repo http://mirrors.aliyun.com/repo/Centos-8.repo

3、运行 yum makecache 生成缓存

1
2
yum clean all
yum makecache

二、安装 Docker

1、修改 Docker 源为阿里云

Docker 源配置文件

1
2
3
4
5
6
7
[root@centos ~]# cat /etc/yum.repos.d/docker-ce.repo
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

2、安装 docker-ce

默认安装:

1
2
3
4
5
6
7
8
9
[root@centos /etc/yum.repos.d]# yum install -y docker-ce
上次元数据过期检查:0:02:30 前,执行于 2021年03月23日 星期二 10时56分16秒。
错误:
问题: package docker-ce-3:20.10.5-3.el7.x86_64 requires containerd.io >= 1.4.1, but none of the providers can be installed
- cannot install the best candidate for the job
- package containerd.io-1.4.3-3.1.el7.x86_64 is filtered out by modular filtering
- package containerd.io-1.4.3-3.2.el7.x86_64 is filtered out by modular filtering
- package containerd.io-1.4.4-3.1.el7.x86_64 is filtered out by modular filtering
(尝试添加 '--skip-broken' 来跳过无法安装的软件包 或 '--nobest' 来不只使用最佳选择的软件包)

centos 官方源的 containerd.io 版本太低,无法安装。
可以在 docker 官方源找到合适的版本,手动安装。

Docker 官方源:https://download.docker.com/linux/centos/
Docker 阿里云源:https://mirrors.aliyun.com/docker-ce/linux/centos/

从阿里云强制安装 containerd.io

1
yum install  --allowerasing -y https://mirrors.aliyun.com/docker-ce/linux/centos/8/x86_64/stable/Packages/containerd.io-1.4.4-3.1.el8.x86_64.rpm

安装 docker-ce 并设置权限

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 安装 Docker
yum install -y docker-ce

# 启动Docker服务
sudo systemctl start docker && sudo systemctl status docker

# 设置开机自启动
sudo systemctl enable docker

# 建议添加普通用户至 Docker 组,并以普通用户运行 Docker。
sudo usermod -aG docker $USER

# 生效组用户变更配置
newgrp docker

3、修改 docker 源

配置文件路径为: /etc/docker/daemon.json。
没有该文件的话,请先建一个。

1
nano  /etc/docker/daemon.json

配置文件内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"registry-mirrors" : [
"https://mirror.ccs.tencentyun.com",
"http://registry.docker-cn.com",
"http://docker.mirrors.ustc.edu.cn",
"http://hub-mirror.c.163.com"
],
"insecure-registries" : [
"registry.docker-cn.com",
"docker.mirrors.ustc.edu.cn"
],
"debug" : true,
"experimental" : true
}

建议使用阿里云,配置方式参见阿里云文档。

4、安装 docker-compose

运行命令:

1
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

docker-compose 不同版本的 yml 配置文件有差异。

使用国内源:

1
curl -L https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

给 docker-compose 执行权限,运行命令:

1
chmod +x /usr/local/bin/docker-compose

安装检查:

1
docker-compose --version