Solve DNS Resolution in Other Containers when using Docker pihole


When using docker pihole container as the sole DNS on the network, other containers cannot resolve DNS.


  • Other containers unable to resolve DNS
  • using nslookup in other containers gives erros stating something like
    ;; reply from unexpected source:, expected
    where is the pihole DNS and is the docker bridge network gateway
  • pihole logs show that the queries from other containers are arriving, forwarding, and being responded to as far as pihole knows.


I think it's because Docker does shenanigans with DNS so that it can do automated name resolution based on container names. The iptables Docker puts in place don't seem to be properly masquerading the IP of the DNS, so the container thinks its DNS request are being intercepted and ignores the responses.


Bind the DNS listening port to the specific external IP you want to listen on in the docker run or docker-compose file. e.g. my docker compose went from this:

      - "53:53/tcp"
      - "53:53/udp"
      #- "67:67/udp"
      - "81:80/tcp"
      - "443:443/tcp"

to this:

      - "53:53/tcp"
      - ""
      #- "67:67/udp"
      - "81:80/tcp"
      - "443:443/tcp"

I imagine the same might need to be done for 53/tcp as well, though I haven't worked that yet since I don't use DNS over TCP.


I had the very same problem: all devices in the network including the raspberry pi itself could use the pihole as the new DNS server... except inside the other containers running on the raspberry pi.

Your solution - using the local IP address of the raspberry pi - worked! I don't know how you manage to find that :slight_smile: .

Thank you very much! :pray:

Any thoughts as to get this working while using --net=host?

Found It - need to use listen-address and bind-interfaces[1] to force Pihole on the specific IP/Interface. Now containers can successfully resolve internally.

[1] Make pihole-FTL bind only on certain IPs [v4.0]

Thank you. This solved my problem why Nextcloud and other containers couldn't resolve all addresses.