Docker DNS settings

2019-08-02 08:49发布

问题:

I try create docker container with custom network and dos settings.

docker network create --driver=bridge --opt "com.docker.network.bridge.enable_ip_masquerade"="true" --opt "com.docker.network.bridge.enable_icc"="true" --opt="com.docker.network.driver.mtu"="1500" --opt="com.docker.network.bridge.host_binding_ipv4"="0.0.0.0" net

--

docker run --dns 10.0.0.2 --network=net busybox cat /etc/resolv.conf

nameserver 127.0.0.11 options ndots:0

Else if I use standard network all work fine

docker run --dns 10.0.0.2 --network=bridge busybox cat /etc/resolv.conf

nameserver 10.0.0.2

回答1:

As of Docker 1.10, DNS is managed differently for user-defined networks. DNS for the default bridge network is unchanged for backwards compatibility. In a user-defined network, docker daemon uses the embedded DNS server. According to the documentation found here:

https://docs.docker.com/engine/userguide/networking/configure-dns/

--dns=[IP_ADDRESS...]   The IP addresses passed via the --dns option is used by the embedded 
                        DNS server to forward the DNS query if embedded DNS server is unable
                        to resolve a name resolution request from the containers. These 
                        --dns IP addresses are managed by the embedded DNS server and will not
                        be updated in the container’s /etc/resolv.conf file.

So, the DNS nameserver will be used, it just is not visible in the container's /etc/resolv.conf.