docker内部dns解析速度慢或超时

docker内部dns解析速度慢或超时,dns,docker,Dns,Docker,在主机上,查找域的速度非常快。但在docker容器中,它的容量要大得多 速度较慢,有时超时 主机是一个虚拟主机,它的dns服务器地址是127.0.0.1(奇怪但真实)。所以我尝试在容器中修改/etc/resolv.conf,并将dns服务器设置为172.x(主机地址)。结果,我没有看到任何好的效果 我还尝试将容器的dns服务器设置为自建(101.x),但查找域的速度仍然很慢。另一件奇怪的事情是ping101.x非常快 我对这种现象感到困惑,任何人都可以解释和帮助吗?我不知道为什么在容器中解析DN

在主机上,查找域的速度非常快。但在docker容器中,它的容量要大得多
速度较慢,有时超时

主机是一个虚拟主机,它的dns服务器地址是127.0.0.1(奇怪但真实)。所以我尝试在容器中修改/etc/resolv.conf,并将dns服务器设置为172.x(主机地址)。结果,我没有看到任何好的效果

我还尝试将容器的dns服务器设置为自建(101.x),但查找域的速度仍然很慢。另一件奇怪的事情是ping101.x非常快


我对这种现象感到困惑,任何人都可以解释和帮助吗?

我不知道为什么在容器中解析DNS会很慢,但我有在docker容器中解析DNS的过程

验证DNS解析问题:

   # docker run busybox nslookup google.com
    Server:    8.8.8.8
    Address 1: 8.8.8.8
    nslookup: can't resolve 'google.com'
# 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
# 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
# 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
查找计算机中使用的DNS服务器

# nm-tool  |grep DNS
    DNS:             172.24.100.50
    DNS:             10.1.100.50
使用解决DNS问题的上述步骤中找到的DNS IP再次运行:

   # docker run busybox nslookup google.com
    Server:    8.8.8.8
    Address 1: 8.8.8.8
    nslookup: can't resolve 'google.com'
# 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
# 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
# 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
要永久解决此问题,请将以下内容添加到新文件中:

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

重新启动docker服务并再次验证:

   # docker run busybox nslookup google.com
    Server:    8.8.8.8
    Address 1: 8.8.8.8
    nslookup: can't resolve 'google.com'
# 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
# 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
# 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
通过运行容器进行检查:

   # docker run busybox nslookup google.com
    Server:    8.8.8.8
    Address 1: 8.8.8.8
    nslookup: can't resolve 'google.com'
# 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
# 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
# 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

希望这有帮助。

遇到同样的问题,您是否已解决?很遗憾,没有。您使用的是什么图像版本?对于我来说是alpine,它仍然有dns解析的bug,请参阅