【问题标题】:Dockerfile Error while giving RUN command给出 RUN 命令时出现 Dockerfile 错误
【发布时间】:2020-12-12 17:32:37
【问题描述】:

我正在尝试学习 Docker,并且我在 CentOS8 上使用 Oracle VMware。我正在尝试构建一个 Dockerfile。以下是文件 Dockerfile 的内容:

FROM centos

RUN yum -y install httpd

当我构建时,它会抛出以下错误:

[arijhit@localhost docker-images]$ docker build --tag centos_apache:v1 .

Sending build context to Docker daemon  2.048kB

Step 1/2 : FROM centos
 ---> 0d120b6ccaa8

Step 2/2 : RUN yum -y install httpd
 ---> Running in 1f20ba141039
CentOS-8 - AppStream                            0.0  B/s |   0  B     00:30    

Errors during downloading metadata for repository 'AppStream':
  - Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org]

Error: Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org]**

The command '/bin/sh -c yum -y install httpd' returned a non-zero code: 1

有人可以帮忙解决这个问题吗?

编辑:

嗨 @Uberhumus 这是 CentOS docker 镜像对你所说的命令的响应

[arijhit@localhost ~]$ docker run -t -d centos 60566bb1a2ef808c59c0374c0e9753bc26f0098c8b54c438e7742af418beae3a

[arijhit@localhost ~]$ docker p
CONTAINER ID        IMAGE             COMMAND                  CREATED             STATUS              PORTS NAMES
60566bb1a2ef        centos              "/bin/bash"              20 seconds ago      Up 8 seconds                            laughing_greider
5d3efb03c67a        nginx:alpine        "/docker-entrypoint.…"   6 minutes ago       Up 5 minutes        80/tcp              kind_tesla

[arijhit@localhost ~]$ docker exec -it laughing_greider /bin/bash

[root@60566bb1a2ef /]# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=115 time=31.4 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=115 time=168 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=115 time=47.3 ms 
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 5ms 
rtt min/avg/max/mdev = 31.357/82.241/168.110/61.064 ms

[root@60566bb1a2ef /]# yum check-update
Failed to set locale, defaulting to C.UTF-8
CentOS-8 - AppStream 0.0  B/s |   0  B     00:30
Errors during downloading metadata for repository 'AppStream':
  - Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org] Error: Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org]

[root@60566bb1a2ef /]# yum -y install httpd
Failed to set locale, defaulting to C.UTF-8
CentOS-8 - AppStream 0.0  B/s |   0  B     00:30
Errors during downloading metadata for repository 'AppStream':
  - Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org] Error: Failed to download metadata for repo 'AppStream': Cannot prepare internal mirrorlist: Curl error (6): Couldn't resolve host name for http://mirrorlist.centos.org/?release=8&arch=x86_64&repo=AppStream&infra=container [Could not resolve host: mirrorlist.centos.org]

【问题讨论】:

  • 你尝试过做什么?具体来说,您是否尝试运行“docker run -it centos /bin/sh”并在其中运行“yum -y install httpd”?它至少会让你看到错误。
  • 您的主机是否在公司代理或类似的东西后面运行?
  • @Uberhumus - 我尝试使用 root 访问权限运行 yum update -y。由于我正在创建 docker 文件并需要构建它,我是否应该将“docker run -it centos /bin/sh”放入 docker 文件中。或者您希望我在构建 Dockerfile 之前将其作为命令行运行。
  • @agentsmith - 这是我的个人笔记本电脑,所以没有公司防火墙或任何代理。我正在运行 Windows 10 作为通过 OracleVM 运行 CentOS 的主机。因此,与我的主机 Windows 连接的 Wifi 相同,它也被用于为我的虚拟机提供 Internet 连接。
  • @arijhit,你能试试这些并报告结果吗:在运行的 CentOS docker 中尝试 ping 8.8.8.8 如果可行,尝试 'yum check-update' 然后 'yum -y install httpd'

标签: dockerfile yum centos8


【解决方案1】:

亲爱的,以下解决了我的问题。

firewall-cmd --permanent --zone=trusted --add-interface=docker0

firewall-cmd --reload

在这里找到它: https://forums.centos.org/viewtopic.php?f=54&t=74270

非常感谢这里的每一个人...

【讨论】:

    【解决方案2】:

    我尝试构建您的 Dockerfile,但我也遇到了一个错误,尽管是另一个错误。

    以下分别为 CentOS 7 和 CentOS 8 工作的 Dockerfile:

    FROM centos:7
    
    RUN yum -y install httpd
    
    EXPOSE 80
    
    ENTRYPOINT [ "/usr/sbin/httpd" ]
    CMD [ "-D", "FOREGROUND"]
    

    FROM centos:8
    
    RUN yum clean all && \
        yum -y update && \
        yum -y install httpd
    
    EXPOSE 80
    
    ENTRYPOINT [ "/usr/sbin/httpd" ]
    CMD [ "-D", "FOREGROUND"]
    

    让我知道其中任何一个是否适合您。

    编辑:

    如果你需要的话,我把预建的图片here 放上去。

    编辑 2:

    如果上述 Dockerfile 没有为您构建,那么很可能是 Docker 的 DNS 有问题。请按照this article 中的步骤验证该假设并可能解决问题。

    【讨论】:

    • 这些都不起作用。我编辑了您的评论以提供整个输出,不知何故该帖子未获得批准。我无法在 cmets 框中发布详细信息。但是不,'RUN yum' 命令对两个版本都给出了错误。如果您有任何想法,请告诉我。此外,由于我试图从 Dockerfile 创建图像文件,因此我没有下载您的预构建图像。
    • 您的编辑被拒绝了,因为您应该在问题中提供有关问题的所有信息 - 包括运行可能答案中提供的任何命令的结果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    • 2018-03-25
    • 1970-01-01
    • 2020-06-13
    相关资源
    最近更新 更多