执行`docker build -f ./dockerfile -t mycentos7:v1 .`时 `RUN yum install -y vim` 报错

执行docker build -f ./dockerfile -t mycentos7:v1 .RUN yum install -y vim 报错

1.报错信息


[+] Building 0.9s (5/6)                                                                                                                                                                                                                                     docker:default
 => [internal] load build definition from centos7-dockerfile                                                                                                                                                                                                          0.0s
 => => transferring dockerfile: 188B                                                                                                                                                                                                                                  0.0s
 => [internal] load metadata for docker.io/library/centos:7                                                                                                                                                                                                           0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                                     0.0s
 => => transferring context: 2B                                                                                                                                                                                                                                       0.0s
 => CACHED [1/3] FROM docker.io/library/centos:7                                                                                                                                                                                                                      0.0s
 => ERROR [2/3] RUN yum install -y vim                                                                                                                                                                                                                                0.8s
------                                                                                                                                                                                                                                                                     
 > [2/3] RUN yum install -y vim:                                                                                                                                                                                                                                           
0.409 Loaded plugins: fastestmirror, ovl                                                                                                                                                                                                                                   
0.509 Determining fastest mirrors                                                                                                                                                                                                                                          
0.768 Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container error was
0.768 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
0.770 
0.770 
0.770  One of the configured repositories failed (Unknown),
0.770  and yum doesn't have enough cached data to continue. At this point the only
0.770  safe thing yum can do is fail. There are a few ways to work "fix" this:
0.770 
0.770      1. Contact the upstream for the repository and get them to fix the problem.
0.770 
0.770      2. Reconfigure the baseurl/etc. for the repository, to point to a working
0.770         upstream. This is most often useful if you are using a newer
0.770         distribution release than is supported by the repository (and the
0.770         packages for the previous distribution release still work).
0.770 
0.770      3. Run the command with the repository temporarily disabled
0.770             yum --disablerepo=<repoid> ...
0.770 
0.770      4. Disable the repository permanently, so yum won't use it by default. Yum
0.770         will then just ignore the repository until you permanently enable it
0.770         again or use --enablerepo for temporary usage:
0.770 
0.770             yum-config-manager --disable <repoid>
0.770         or
0.770             subscription-manager repos --disable=<repoid>
0.770 
0.770      5. Configure the failing repository to be skipped, if it is unavailable.
0.770         Note that yum will try to contact the repo. when it runs most commands,
0.770         so will have to try and fail each time (and thus. yum will be be much
0.770         slower). If it is a very temporary problem though, this is often a nice
0.770         compromise:
0.770 
0.770             yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true
0.770 
0.770 Cannot find a valid baseurl for repo: base/7/x86_64
------
centos7-dockerfile:4
--------------------
   2 |     MAINTAINER author
   3 |     
   4 | >>> RUN yum install -y vim
   5 |     
   6 |     CMD /bin/bash
--------------------
ERROR: failed to solve: process "/bin/sh -c yum install -y vim" did not complete successfully: exit code: 1

2. dockerfile文件内容

FROM centos:7
MAINTAINER author

RUN yum install -y vim

CMD /bin/bash

WORKDIR /usr

3.解决方法

FROM centos:7
MAINTAINER zfm

RUN cd /etc/yum.repos.d/ \
&& sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* \
&& sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*  \
&& yum install -y vim

CMD /bin/bash

WORKDIR /usr

posted @ 2024-08-01 21:48  孤勇赠余生  阅读(34)  评论(0编辑  收藏  举报