在阿里云服务器上 docker build 出现错误
Error: Failed to download metadata for repo ‘appstream’: Cannot prepare internal mirrorlist: No URLs in mirrorlist
[root@iZbp18knnewwywd8jkfZ dockerfile]# docker build -f mydockerfile-centos -t mycentos:0.1 .
Sending build context to Docker daemon 2.048kB
Step 1/10 : FROM centos
latest: Pulling from library/centos
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
---> 5d0da3dc9764
Step 2/10 : MAINTAINER suifeng<test@qq.com>
---> Using cache
---> e49f6464cec5
Step 3/10 : ENV MYPATH /usr/local
---> Using cache
---> 758e1e76b032
Step 4/10 : WORKDIR $MYPATH
---> Using cache
---> 25870bf309c1
Step 5/10 : RUN yum -y install vim
---> Running in 16e7a2d64399
CentOS Linux 8 - AppStream 33 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
[root@iZbp18knnewwywd8jkfZ dockerfile]#
尝试过很多解决办法,包括换镜像源,防火墙等等
都没有得到解决
百度了一通说因为centOS8于2021年12月31日停止了源的服务,而现在时间是2022年3月了,所以之前的方法都不行的原因所在(本质是源的问题)。
未具体指明 centos7 的镜像时,它会默认去找最新的镜像,然后就一直失败
然后我将脚本中FROM centos改成指定版本FROM centos:FROM centos7
然后就成功了。。
[root@iZbp18knnewwywd8jkfZ dockerfile]# cat mydockerfile-centos
FROM centos:centos7
MAINTAINER suifeng<test@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
参考文章:https://blog.csdn.net/qq_45662411/article/details/122817998
https://help.aliyun.com/document_detail/405635.html?spm=5176.smartservice_service_chat.0.0.712c3f1bBoZ19I