Docker Community Forums

Share and learn in the Docker community.

Docker container can't use PiHole DNS Server in another container

Hi there,

I’m running Raspbian Release 10 (Kernel Linux 5.4.51-v7+) on a RPi Modell 3 with currently two Docker containers. The first container is the “pihole/pihole:latest” image which works just fine. PiHole runs with the IP address 192.168.178.67/24.

pi@myRPi:~ $ cat /etc/resolv.conf
'# Generated by resolvconf
domain fritz.box
nameserver 192.168.178.67

My router has the IP address 192.168.178.1 and works as a backup DNS server. When creating the second container I’m not able to connect to the internet, unless I add ‘–dns 192.168.178.1’ to the command line.

Ping to the backup DNS server

pi@myRPi:~ $ docker container exec e408c3722e1e ping -c 2 192.168.178.1
PING 192.168.178.1 (192.168.178.1) 56(84) bytes of data.
64 bytes from 192.168.178.1: icmp_seq=1 ttl=63 time=2.53 ms
64 bytes from 192.168.178.1: icmp_seq=2 ttl=63 time=4.81 ms

— 192.168.178.1 ping statistics —
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 2.536/3.675/4.814/1.139 ms

Ping to the PiHole

pi@myRPi:~ $ docker container exec e408c3722e1e ping -c 2 192.168.178.67
PING 192.168.178.67 (192.168.178.67) 56(84) bytes of data.
64 bytes from 192.168.178.67: icmp_seq=1 ttl=64 time=0.255 ms
64 bytes from 192.168.178.67: icmp_seq=2 ttl=64 time=0.254 ms

— 192.168.178.67 ping statistics —
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.254/0.254/0.255/0.015 ms

Both DNS servers are reachable from within the second container.

I’d like to use the PiHole instead of the backup DNS server for the second container, but I don’t know why this doesn’t work.

Any help appreciated.

I don’t quite get what exactly your question ist but:
you can use docker run --dns 192.168.178.67--dns 192.168.178.1 other/container for your second container. Your router/modem will be used as a backup.
In your /etc/resolv.conf set another nameserver record as a backup, namely: nameserver 192.168.178.67

Hope this solved your question,
Cheers!