Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

slow or timeout of dns resolving inside docker

Tags:

docker

dns

On host machine, it's very fast to lookup a domain. But inside docker container, it's much
slower and sometimes timeout.

The host machine is a virtual host, and it's dns server address is 127.0.0.1 (weird but true). So I've tried to modify /etc/resolv.conf inside container and set the dns server to be 172.x (host's address). As a result, I didn't see any good effect.

I've also tried to set the container's dns server to be a self-built one (101.x), but still, it's slow to look up a domain. Another weird thing is that ping 101.x is very fast.

I'm confused about this phenomenon, anyone can explain and help?

like image 339
dastan Avatar asked Dec 26 '14 04:12

dastan


1 Answers

I am not sure of why resolving DNS is slow in the containers, but I have procedure which I follow to resolve the DNS in the docker containers.

To verify DNS resolution issue:

   # docker run busybox nslookup google.com
    Server:    8.8.8.8
    Address 1: 8.8.8.8
    nslookup: can't resolve 'google.com'

Find out the DNS server used in your machine :

# nm-tool  |grep DNS
    DNS:             172.24.100.50
    DNS:             10.1.100.50

Run it again using DNS IP found in the above step which resolves the DNS issue:

# docker run --dns 172.24.100.50 busybox nslookup google.com
Server:    172.24.100.50
Address 1: 172.24.100.50 indc01.radisys.com
Name:      google.com
Address 1: 2607:f8b0:4009:80c::200e ord36s01-in-x0e.1e100.net
Address 2: 172.217.4.110 ord36s04-in-f14.1e100.net

To resolve it permanently add the following content as below to a new file:

root@labadmin-VirtualBox:/home/labadmin# cat /etc/docker/daemon.json
{
    "dns" : ["172.24.100.50", "8.8.8.8"]
}

More info on Docker DNS configuration.

Restart the docker service and verify it again:

# docker run busybox nslookup google.com
Server:    172.24.100.50
Address 1: 172.24.100.50 indc01.radisys.com
Name:      google.com
Address 1: 2607:f8b0:4009:801::200e ord30s31-in-x0e.1e100.net
Address 2: 172.217.4.238 ord30s31-in-f14.1e100.net

Check it by running the container:

# docker run -it e02e811dd08f
/ # ping google.com
PING google.com (172.217.4.238): 56 data bytes
64 bytes from 172.217.4.238: seq=0 ttl=47 time=251.506 ms
64 bytes from 172.217.4.238: seq=1 ttl=47 time=245.621 ms

Hope this helps.

like image 120
Here_2_learn Avatar answered Sep 24 '22 15:09

Here_2_learn