1.安装依赖包
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
2.设置阿里云镜像源
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3.更新 yum 缓存
sudo yum makecache
4.安装 docker-ce
sudo yum install docker-ce
5.启动docker
配置开机启动
sudo systemctl enable docker
启动docker
sudo systemctl start docker
6.配置国内镜像
阿里云提供了镜像源:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
需要阿里云账号登录后你会获得一个专属的地址。
# 创建配置目录
mkdir -p /etc/docker
# 创建配置文件
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://xxxxxxxxxxxxx.mirror.aliyuncs.com"]
}
EOF
# 重新加载配置文件
sudo systemctl reload docker
sudo systemctl daemon-reload
# 重启docker
sudo systemctl restart docker
7. 安装时异常处理
1.问题
执行步骤4时异常
Last metadata expiration check: 0:00:34 ago on Thu 11 Jun 2020 07:38:53 PM CST.
Error:
Problem: package docker-ce-3:19.03.11-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.10-3.2.el7.x86_64 is excluded
- package containerd.io-1.2.13-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.13-3.2.el7.x86_64 is excluded
- 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
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
解决方案
# containerd 版本过旧升级升级即可
dnf install -y https://download.docker.com/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
2.问题
解决方案
sudo vi /etc/yum.repos.d/docker-ce.repo
# baseurl=https://download.docker.com/linux/centos/$releasever/$basearch/stable
# 修改成下面地址
baseurl=https://download.docker.com/linux/centos/7/$basearch/stable
国内docker仓库中心