docker容器内部运行yum时,Cannot retrieve repository metadata (repomd.xml) for repository: base.
当我们在docker容器中运行yum命令安装时:
[root@27fecd731f89 /]# yum -y install mysql
出现如下报错信息:
Loaded plugins: fastestmirror
Determining fastest mirrors
http://mirrors.163.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again
首先我们肯定要想到我们的linux操作系统是否可以上网,如果不能上网,就先配置好网络,修改网卡、ping等等,保证网络是通的。
接下来就是考虑容器内部的yum源问题了
方案一
首先我们想到的肯定是yum源有问题,那么就想到更改yum源的地址,更改为阿里云的源或者清华大学的源。这里我们采用清华大学的yum源
1.首先进入容器内部,执行下面的命令
docker exec -it 容器id|容器名 /bin/bash
cd /etc/yum.repos.d/
ls
更改CentOS-Base.repo里面的源地址
vim CentOS-Base.repo
# 我们只需要将所有的mirrorlist注释掉,然后都添加上清华大学的baseurl地址
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/6.8/os/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/6.8/os/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/6.8/os/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/6.8/os/x86_64/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/6.8/os/x86_64/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
接下来就再次尝试yum安装了。
起初我是没有成功的,接下来我尝试了一下下面这种方法,发现应该是我脑子进水了才会想出这种尝试。最先的想法是,我可不可以更新一下yum源,于是用wget尝试下载aliyun的源,但是发现没有wget,这就很尴尬了,于是用yum wget一下,发现yum没用,这就陷入了死循环了。下面这种方法应该是行不通的,但是你也可以尝试一下将yum源下载到本地,在传到容器里面看是否可以有用!!!我这里就不尝试了,我是后来第一种方案解决的。
方案二
解决:
1.首先进入容器内部,执行下面的命令
docker exec -it 容器id|容器名 /bin/bash
2.接下来,在网上找到合适的yum源,这里采用aliyun的
yum -y insall wget
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
3.执行完毕以后,依次执行以下两句命令:
yum clean all # 清除旧缓存
yum makecache # 安装新的依赖
解决!!!