in Linux

Red Hat 8 安装Docker返回找不到镜像的问题(Status code: 404)

小结

Red Hat 8 yum 指令安装Docker社区版时返回了Status code: 404错误,也就是找不到相应的仓库镜像,进行了解决。

问题

环境: Red Hat 8.3
首先安装了

yum install -y yum-utils

配置Red Hat 8的Docker的镜像仓库,如下:

yum-config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo

配置好后在yum目录下创建了仓库配置文件:/etc/yum.repos.d/docker-ce.repo,内容如下:

[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://download.docker.com/linux/rhel/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/rhel/gpg

以下省略...

使用指令安装docker-ce(社区版)-> yum install docker-ce docker-ce-cli containerd.io,失败返回如下:

Updating Subscription Management repositories.
Docker CE Stable - x86_64 
Errors during downloading metadata for repository 'docker-ce-stable':
- Status code: 404 for https://download.docker.com/linux/rhel/8/x86_64/stable/repodata/repomd.xml 
Error: Failed to download metadata for repo 'docker-ce-stable': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

从以上返回来看,应该是镜像没有找到。

解决

查看Red Hat 8的Docker的镜像仓库,发现有如下内容:

Index of linux/rhel/8/
../
s390x/
source/

根本就没有x86_64这个目录。

正确的地址应该是使用CentOS分支:CentOS的Docker的镜像仓库

解决办法,使用以下sed指令进行修改:

sed -i -e 's/baseurl=https:\/\/download\.docker\.com\/linux\/\(fedora\|rhel\)\/$releasever/baseurl\=https:\/\/download.docker.com\/linux\/centos\/$releasever/g' /etc/yum.repos.d/docker-ce.repo

进行修改后,仓库配置文件:/etc/yum.repos.d/docker-ce.repo,更新后的内容如下:

[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://download.docker.com/linux/centos/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://download.docker.com/linux/rhel/gpg

以下省略...

至此,yum install docker-ce docker-ce-cli containerd.io指令可以成功执行,问题解决。

参考

Red Hat: Unable to install docker on rhel 8 linux
Red Hat 8的Docker的镜像仓库
CentOS的Docker的镜像仓库

Write a Comment

Comment