解决使用Dockerfile更新centos镜像Failed to download metadata for repo‘AppStream’「CentOS」问题

由于docker中的centos镜像是没有vim编辑器,net-tools等功能,于是使用Dockerfile构建新的centos镜像,我的Dockerfile如下(部分无关内容已省略):

        FROM centos
        MAINTAINER ly<[email protected]>
        ENV MYPATH /usr/local
        WORKDIR $MYPATH
        #安装vim编辑器
        RUN yum -y install vim
        #安装ifconfig命令查看网络IP
        RUN yum -y install net-tools
        EXPOSE 80
        CMD echo $MYPATH
        CMD /bin/bash

但是在执行yum -y install vim的时候却报了如下错误

Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
起初我怀疑是网络问题,但是经过排查,网路是没有问题的,后来我通过百度查找资料,发现很多方法都是无法解决,知道我看到一篇文章,centos8的官方镜像已经停止维护,而我docker pull的是默认的last版本,也就是centos8,所以有了以下两种解决办法

1.删除最新镜像,拉取7版本的镜像

2.在Dockerfile中安装命令之前,执行修改配置,将镜像改为阿里云的

Dockerfile命令如下

FROM centos
MAINTAINER ly<[email protected]>
ENV MYPATH /usr/local
WORKDIR $MYPATH
RUN cd /etc/yum.repos.d/
RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
#安装vim编辑器
RUN yum -y install vim
#安装ifconfig命令查看网络IP
RUN yum -y install net-tools
EXPOSE 80
CMD echo $MYPATH
CMD /bin/bash

猜你喜欢

转载自blog.csdn.net/qq_28174545/article/details/123347837