Slow or dns timeout allowing inside dockers

It is very fast to find a domain on the host machine. But inside the docker container, it is a lot slower, and sometimes timed out.

The host machine is a virtual host, and the DNS server address is 127.0.0.1 (strange but true). So I tried to change /etc/resolv.conf inside the container and set the DNS server as 172.x (host address). As a result, I did not see any good effect.

I also tried to set the container dns server as self-tuning (101.x), but still it is slowly looking for the domain. Another weird thing: ping 101.x is very fast.

I am confused by this phenomenon, can anyone explain and help?

+5
source share
1 answer

I'm not sure why DNS resolves slowly in containers, but I have a procedure that I use to resolve DNS in docker containers.

To check the 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 on your computer :

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

Run it again using the DNS-IP found in the previous step, which fixes the DNS problem:

 # 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 permanently resolve it, add the following content as shown below to the new file:

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

Learn more about Docker DNS Configuration .

Restart the docker service and confirm 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 

Test 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.

0
source

Source: https://habr.com/ru/post/1209904/


All Articles