skip to Main Content

I am trying to learn Docker and I am on Oracle VMware on CentOS8. I am trying to build a Dockerfile. Here is the content of the file Dockerfile:

FROM centos

RUN yum -y install httpd

When I build, it throws the error below:

[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

Can someone please help rectify this?

Edit:

Hi @Uberhumus Here is the response from CentOS docker image for the commands you said

[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]

2

Answers


  1. Chosen as BEST ANSWER

    Dear All the following solved my problem.

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

    Found it here: https://forums.centos.org/viewtopic.php?f=54&t=74270

    Many thanks to everyone here...


  2. I tried to build your Dockerfile and I’ve gotten an error too, albeit a different one.

    Below are working Dockerfiles for CentOS 7 and CentOS 8 respectively:

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

    and

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

    Let me know if either of those works for you.

    Edit:

    I put the prebuilt images here if you need them.

    Edit 2:

    If the above Dockerfiles do not build for you, then it’s most likely a problem with Docker’s DNS. Please follow the steps in this article to verify that hypothesis and possibly resolve the problem.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search