FROM centos:7MAINTAINER zhangsan zs@163.comLABEL version="1.0" description="this is a custom centos image"ENV WORKPATH /usr/localWORKDIR $WORKPATHRUN yum -y install vim net-tools wgetCMD /bin/bash

docker build -t cento7:1.0 .#执行以上docker file报错

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

尝试过更换yum源、检查网络等等,均无法解决。

最后将docker 重启了,但是生产环境需要谨慎重启docker

systemctl restart docker

再次执行

[root@test hw]# docker build -t cento7:1.0 .[+] Building 64.5s (5/6) => [internal] load .dockerignore0.0s0.0s[+] Building 64.7s (5/6) 0.0s0.0s rnal] load build definition from Dockerfile 0.0s0.0s => [internal] load .dockerignore0.0s0.0s0.0sernal] load metadata for docker.io/library/centos:70.0s0.0s => => transferring context: 2B0.0s0.0s0.0sED [2/3] WORKDIR /usr/local0.0s0.0s => [internal] load build definition from Dockerfile64.5s 64.2s0.0s Running transaction check=> => transferring dockerfile: 302B 0.0s Transaction test succeeded => [internal] load metadata for docker.io/library/centos:70.0s Installing : gpm-libs-1.20.7-6.el7.x86_641/35=> [1/3] FROM docker.io/library/centos:70.0s => CACHED [2/3] WORKDIR /usr/local0.0s => [3/3] RUN yum -y install vim net-tools wget[+] Building 64.8s (5/6)Running transaction check=> [internal] load .dockerignore0.0s Running transaction test => => transferring context: 2B0.0s Transaction test succeeded => [internal] load build definition from Dockerfile 0.0s Running transaction=> => transferring dockerfile: 302B 0.0s Installing : gpm-libs-1.20.7-6.el7.x86_641/35=> [internal] load metadata for docker.io/library/centos:70.0s Installing : 2:vim-filesystem-7.4.629-8.el7_9.x86_64 2/35=> [1/3] FROM docker.io/library/centos:70.0s => CACHED [2/3] WORKDIR /usr/local[+] Building 102.5s (7/7) FINISHED=> [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load build definition from Dockerfile0.0s => => transferring dockerfile: 302B0.0s => [internal] load metadata for docker.io/library/centos:7 0.0s => [1/3] FROM docker.io/library/centos:7 0.0s => CACHED [2/3] WORKDIR /usr/local 0.0s => [3/3] RUN yum -y install vim net-tools wget90.4s => exporting to image 11.9s => => exporting layers11.9s => => writing image sha256:9c42ab93536027309742507295ac8481238448ce43c8cd0719c1750862a102a30.0s=> => naming to docker.io/library/cento7:1.0

发现问题解决。

[root@test hw]# docker imagesREPOSITORYTAG IMAGE ID CREATEDSIZE cento71.0 9c42ab935360 18 seconds ago 469MBhello-my-word latest280551f2b1ed 2 hours ago861kBcentos7 eeb6ee3f44bd 21 months ago204MB

可参考学习!