Search code examples
dockerdns

Set the Docker DNS timeout for embedded DNS


In docker when the embedded DNS is used because of docker networks, my application has the following DNS

search ipa.pain.com pain.com
nameserver 127.0.0.11
options rotate timeout:1 ndots:0

the setting timeout:1 appears to come from the host which uses that setting to fall through DNS. However this setting appears to make the Docker DNS retry the same entry and therefore cannot fall through DNS. Is there a way for me to override this?


Solution

  • For example, on my host PC settings:

    'cat /etc/resolv.conf':

    nameserver 8.8.8.8
    options rotate timeout:1 ndots:0
    

    I can update this value on the container in 2 ways:

    First Way: Adding DNS and DNS opt values in "/etc/docker/daemon.json", then restarting the Docker service (systemctl restart docker) or restarting the VM/PC.

    {
    "dns": [ "127.0.0.1"],
    "dns-opts": ["timeout:5", "rotate", "ndots:0"]
    }
    

    Test: New DNS and DNS option values are updated on the container.

    docker run --rm ubuntu:latest cat /etc/resolv.conf
    nameserver 127.0.0.1
    options timeout:5 rotate ndots:0
    

    Second Way: Running the container with DNS and DNS opt paramaters. Only created container runs these values. Each time parameters are required to run.

    Test:

    docker run --rm --dns 127.0.0.1 --dns-opt timeout:10 --dns-opt rotate --dns-opt ndots:0 ubuntu:latest cat /etc/resolv.conf
    nameserver 127.0.0.1
    options timeout:10 rotate ndots:0