Error: Failed to download metadata for repo ‘appstream‘: Cannot prepare internal mirrorlist: No URLs

在阿里云服务器上 docker build 出现错误
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs


[root@Agustletmen dockerfile]# docker run -f /home/dockerfile/mydockerfile-centos -t mycentos:0.1 .
unknown shorthand flag: 'f' in -f
See 'docker run --help'.
[root@Agustletmen dockerfile]# docker build -f /home/dockerfile/mydockerfile-centos -t mycentos:0.1 .
Sending build context to Docker daemon  2.048kB
Step 1/10 : FROM centos
 ---> 5d0da3dc9764
Step 2/10 : MAINTAINER qx<3066686488@qq.com>
 ---> Using cache
 ---> f25871e5ab22
Step 3/10 : ENV MYPATH /usr/local
 ---> Using cache
 ---> 48e5adc23206
Step 4/10 : WORKDIR $MYPATH
 ---> Using cache
 ---> 3c7e4ff9ca5d
Step 5/10 : RUN yum -y install vim
 ---> Running in 71b82bf5f0ac
CentOS Linux 8 - AppStream                       30  B/s |  38  B     00:01
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
The command '/bin/sh -c yum -y install vim' returned a non-zero code: 1

原因:因为centOS8于2021年12月31日停止了源的服务,而现在时间是2022年3月了,所以之前的方法都不行的原因所在(本质是源的问题)。

解决方案:未具体指明 centos7 的镜像时,它会默认去找最新的镜像,然后就一直失败
因为我的宿主机的是centos 7.9.2009的
因此在下载的时候下载了7.9.2009
docker pull centos:7.9.2009
将脚本中FROM centos改成指定版本FROM centos:7.9.2009
即可成功

FROM centos:7.9.2009
MAINTAINER qx<888666@qq.com>

ENV MYPATH /usr/local
WORKDIR $MYPATH

RUN yum -y install vim
RUN yum -y install net-tools

EXPOSE 80

CMD echo $MYPATH
CMD echo "-----end----"
CMD /bin/bash

猜你喜欢

转载自blog.csdn.net/weixin_50569789/article/details/124649895