DNS Server in Docker Container

I have the DNS server Unbound in a docker container. This container has the following port mapping in the docker deamon:
0.0.0.0:53->53/tcp, 0.0.0.0:53->53/udp

The docker host has the IP address 192.168.24.5 and a local DHCP server announces the host’s IP as the local DNS server. This works fine all over my local network.
The host itself uses this DNS server through the IP 192.168.24.5. That’s the address that is put to the host’s /etc/resolv.conf. (I know it would not work with docker if there was 127.0.0.1 as the nameserver address.)

  • Using docker-selenium to test internal host behind VPN
  • Spring Boot External Configuration when using Docker
  • Docker error link folder Read-only file system
  • Why does Liquibase migration on MySQL database die after acquiring lock on DC/OS (worked fine with docker-compose)?
  • Using SSL on nginx in a Docker container hosted on Jelastic
  • Load balancing express app instances
  • I have some other docker containers and they are supposed to use this DNS server as well. The point is, they don’t.

    What actually happens is this:
    Whithin a random container I can ping the host’s address as well as the address of the unbound-container. But when I use dig inside a container I get these results:

    # dig @172.17.0.6 ...
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 22778
    ;; flags: qr rd ad; QUERY: 0, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
    ;; WARNING: recursion requested but not available

    # dig @192.168.24.5 ...
    ;; reply from unexpected source: 172.17.0.1#53, expected 192.168.24.5#53

    This looks like some internal DNS server intercepts the queries and tries to answer them. That would be fine if it would use the host’s DNS server to get an answer, but it doesn’t. DNS doesn’t work at all in the containers.

    Am I doing wrong or is docker doing something it should not ?

  • How to use mysql docker container as mysql server for local development?
  • Docker - Limit mounted volume size
  • Deploying Java app to Docker image
  • how to make docker client connect to docker daemon over http
  • Confused about which docker driver running which iso
  • How to install telnet in Docker for Windows 10
  • One Solution collect form web for “DNS Server in Docker Container”

    The issue is iptables UDP nat for DNS server. You’re querying the host IP while it’s the docker bridge network’s response.

    To fix this issue in at least to ways:

    • Use container IP (DNS container) as DNS resolver if possible.

    or

    • Provide --net=host to your DNS server container and remove port mapping altogether. Then host IP DNS would work as expected.
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.