1. 卸载旧版本
sudo yum remove \
docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
2. 安装必要的系统工具
sudo yum install -y \
yum-utils \
device-mapper-persistent-data \
lvm2
3. 设置稳定的下载来源(阿里云)
sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3.1 近期发现Centos8会报错,错误如下
非Centos8略过
Error:
Problem: package docker-ce-3:19.03.9-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
解决办法:
#下载 containerd
[root@ebs-55853 down]# wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.13-3.1.el7.x86_64.rpm
#安装 containerd
[root@ebs-55853 down]# yum -y install ./containerd.io-1.2.13-3.1.el7.x86_64.rpm
4. 搜索docker版本
yum list docker-ce --showduplicates | sort -r
查找结果为:
[root@ebs-55853 down]# yum list docker-ce --showduplicates | sort -r
* updates: mirror.lzu.edu.cn
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
Installed Packages
* extras: mirror.lzu.edu.cn
docker-ce.x86_64 3:19.03.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.5-3.el7 @docker-ce-stable
docker-ce.x86_64 3:19.03.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-stable
5. 通过查找到的版本,使用下面命令进行安装。
#yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
#<VERSION_STRING> 替换为查找到需要安装的版本号
#如上面最新版本是3:19.03.5-3.el7 ,那么命令行为
yum install docker-ce-19.03.5 docker-ce-cli-19.03.5 containerd.io
6. 安装完成,启动docker
systemctl start docker
7. 查看当前版本
docker -v
8. 设置开机启动
systemctl enable docker