Page 1 of 1

Docker containers cannot resolve DNS

Posted: 2020/05/02 14:35:55
by fearlessfara
I just installed docker on CentOS 8. Everything went fine, I’ve run the hello_world test container and the result was successful.
The issue is that inside the containers I cannot resolve any DNS queries. For example when I type ping 8.8.8.8 (on any kind of base container such as ubuntu os centOS) i get the correct answer but when I try running ping google.com I don’t get any answer, meaning that the container is unable to resolve the DNS for any URL.

I’ve also tried running a base container like this:

Code: Select all

docker run busybox ping -c 1 192.203.230.10
ang I’m getting this (correct) output:

Code: Select all

    [server@localhost ~]$ docker run busybox ping -c 1 192.203.230.10
    PING 192.203.230.10 (192.203.230.10): 56 data bytes
    64 bytes from 192.203.230.10: seq=0 ttl=51 time=32.413 ms
    --- 192.203.230.10 ping statistics ---
    1 packets transmitted, 1 packets received, 0% packet loss
    round-trip min/avg/max = 32.413/32.413/32.413 ms
But now trying resolving the domain google.com with the command:

Code: Select all

docker run busybox nslookup google.com
I get this output:

Code: Select all

[server@localhost ~]$ docker run busybox nslookup google.com
    nslookup: write to '8.8.8.8': No route to host
    nslookup: write to '8.8.4.4': No route to host
    ;; connection timed out; no servers could be reached
I’m finding this problem really frustrating since I’ve not found a way to solve it. I'm attaching for completeness a `cat /etc/resolv.conf ` of both the machine running docker and the container itself

On the machine with CentOS 8:

Code: Select all

[server@localhost ~]$ cat /etc/resolv.conf 
    # Generated by NetworkManager
    nameserver 8.8.8.8
    nameserver 8.8.4.4
Inside any docker container:

Code: Select all

bash-4.4# cat /etc/resolv.conf
    # Generated by NetworkManager
    nameserver 8.8.8.8
    nameserver 8.8.4.4
Which looks like a normal and working configuration, but when i try to ping google.com (inside the containers) I get:

Code: Select all

bash-4.4# ping google.com
    ping: google.com: Try again

Tell me which command to run to get any info you’d find useful to help me solve this issue, I’ll post it here asap.

Re: Docker containers cannot resolve DNS

Posted: 2020/05/03 10:50:44
by aks
Have a look at: https://docs.docker.com/config/containe ... etworking/ especially the --dns args.

Re: Docker containers cannot resolve DNS

Posted: 2020/05/03 17:09:31
by fearlessfara
aks wrote:
2020/05/03 10:50:44
Have a look at: https://docs.docker.com/config/containe ... etworking/ especially the --dns args.
Thanks for the info, I think that your suggestion could have solved my problem too, but since I don't really wanna specify for each container the DNS I found out that the solution to the problem seems to be adding docker as a trusted interface on firewalld using the command:

Code: Select all

firewall-cmd --permanent --zone=trusted --add-interface=docker0
and then reloading firewalld with:

Code: Select all

firewall-cmd --reload
After it should work correctly, at least it did for me (remember to reboot)

Re: Docker containers cannot resolve DNS

Posted: 2020/06/28 09:14:16
by johnjamesmarsh
firewall-cmd --permanent --zone=trusted --add-interface=docker0
Thankyou @fearlessfara you have solved my issue too :-)

Re: Docker containers cannot resolve DNS

Posted: 2020/08/12 12:29:44
by bripakes
I spent hours on this and this fixed it! Thank you SO much for posting this fix!