首页 文章

dns在docker内部解析缓慢或超时

提问于
浏览
5

在主机上,它是多少's very fast to lookup a domain. But inside docker container, it'
慢,有时超时 .

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

我也尝试将容器的dns服务器设置为自构建的服务器(101.x),但是,查找域名的速度很慢 . 另一个奇怪的事情是ping 101.x非常快 .

我对这种现象感到困惑,有谁能解释和帮助?

1 回答

  • 1

    我不确定为什么在容器中解析DNS的速度很慢,但是我有一些程序可以解决Docker容器中的DNS问题 .

    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"]
    }
    

    有关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
    

    希望这可以帮助 .

相关问题