华为云安装docker
华为云安装docker
最近搞了台华为云服务器,系统为CentOS8.2,然后想要先装个docker,这里简单记录下过程
1.网上方法
1.卸载系统之前可能安装的 docker(防止冲突)
卸载系统之前可能安装的 docker(防止版本不一致,发生冲突)
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
2、安装 Docker-CE 基本环境
安装必须的依赖
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
这一步出了问题,无法解析host
CentOS Linux 8 - AppStream 0.0 B/s | 0 B 00:00
Errors during downloading metadata for repository 'appstream':
- Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=stock [Could not resolve host: mirrorlist.centos.org]
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=stock [Could not resolve host: mirrorlist.centos.org]
问题出现的原因是因为 CentOS Linux 8已于 2021年12月31日停止更新和维护,由于CentOS 团队从官方镜像中移除CentOS 8的所有包,所以在使用yum源安装或更新会报上述失败错误。(参考https://blog.csdn.net/lxcw_sir/article/details/140185068)
解决办法:
进入仓库源文件夹下
cd /etc/yum.repos.d/
修改镜像配置内容
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
清空原有缓存,并重新生成
yum clean all && yum makecache
更新软件包
yum update -y
接着设置 docker repo 的 yum 位置
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
安装 docker,以及 docker-cli
sudo yum install docker-ce docker-ce-cli containerd.io
这一步无法安装,总是显示超时
Docker CE Stable - x86_64 0.0 B/s | 0 B 01:30
Errors during downloading metadata for repository 'docker-ce-stable':
- Curl error (28): Timeout was reached for https://download.docker.com/linux/centos/8/x86_64/stable/repodata/repomd.xml [Connection timed out after 30000 milliseconds]
- Curl error (28): Timeout was reached for https://download.docker.com/linux/centos/8/x86_64/stable/repodata/repomd.xml [Operation timed out after 30000 milliseconds with 0 out of 0 bytes received]
- Curl error (35): SSL connect error for https://download.docker.com/linux/centos/8/x86_64/stable/repodata/repomd.xml [OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to download.docker.com:443 ]
Error: Failed to download metadata for repo 'docker-ce-stable': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
实在没辙,结果一搜,发现华为云官网给出了安装docker方法,赶紧尝试一番
2.官网方法
1.添加yum源。
yum install epel-release -y
yum clean all
2.安装yum-util。
yum install -y yum-utils device-mapper-persistent-data lvm2
这里我之前安装成功了,但是重新安装时显示超时,不过都安装过了就没有问题了
3.设置docker yum源。
yum-config-manager --add-repo https://mirrors.huaweicloud.com/docker-ce/linux/centos/docker-ce.repo
sed -i 's+download.docker.com+mirrors.huaweicloud.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
4.安装并运行Docker。
yum -y install docker-ce
systemctl enable docker
systemctl start docker
5.检查安装结果。
docker --version