Can't get DHCP to work with Docker

Jeff;

I too am trying to enable Pi-Hole as both a DNS and DHCP server from a docker container running on windows machine. Right now my Pi_hole is blocking ads, but I cannot get the DHCP server to work from a container. Every time I enable it I get a pi-hole error message and it breaks the dashboard.

Very frustrating!

Your post above is helpful and it seems like you had a similar objective.

Have you modified this docker run command you posted since then (learned any more lessons?)

Would you be so kind as to tell me what those -V lines do and what (if anything) I need to do on the machine side to set them up? (is there anything I need to put in those paths?)

Thanks In advance if you are able to help!

As often, there is more than one way to reach your goal.

Pi-hole's documentation on Docker DHCP and Network Modes covers quite a few options on how to get DHCP to work with a dockered Pi-hole.

This a Docker question.
Using volumes allows you to persist a specific part of container's data so it survives a container restart. That's also Docker's preferred way of doing so. Docker offers and/or requires different ways for defining volumes in different usage scenarios, though. If you define volumes, Docker creates them automatically upon starting a container if they would not already exist.
For further details, see Docker's documentation on volumes.

The sample configuration from Pi-hole's Quick Start Docker documentation recommends to define two volumes. Those would persist data from /etc/pihole and /etc/dnsmasq.d, in order to keep your Pi-hole's configuration and long-term query database.

below is my current docker run command, I believe I had recently modified it last time I pulled the latest image as there were some breaking changes.

docker run \
--name pihole \
--hostname pihole \
--detach --net=host --cap-add=NET_ADMIN \
-e DHCP_ROUTER=192.168.0.1 -e DHCP_ACTIVE=true -e DHCP_START=192.168.0.50 -e DHCP_END=192.168.0.150 -e WEB_PORT=980 -e INTERFACE=br0 -e WEBPASSWORD=password -e ADMIN_EMAIL=adminemail \
-e WEBTHEME=default-dark -e DHCP_rapid_commit=true -e WEBUIBOXEDLAYOUT=boxed -e PIHOLE_DNS_='127.0.0.1;9.9.9.9;149.112.112.112;8.8.8.8;8.8.4.4' --dns=127.0.0.1 --dns=9.9.9.9 \
--restart=unless-stopped \
-v /etc/timezone:/etc/timezone:ro \
-v /etc/pihole/pihole:/etc/pihole \
-v /etc/pihole/pihole/dnsmasq.d:/etc/dnsmasq.d \
pihole/pihole:latest

For the DHCP part to work the important parts are --net=host --cap-add=NET_ADMIN and setting the INTERFACE to the correct nic especially if you have multiple on the host machine.

As @Bucking_Horn mentioned the -v or volumes map host directories to the docker container directories which allows persistence (and easy configuration changes between instances of the container if need be). I will point out that I am on a linux host and something that I have adopted across many of my docker containers is to map a volume for /etc/timezone which is so that my containers have the same timezone settings as my host and if there are changes made they will get picked up next time the container is started. Windows does not have this so you will need to change this to reflect what is recommended in the Docker documentation for pihole.

1 Like

I surely appreciate you taking the time and sending this. Very helpful. I will have to figure out the INTERFACE -- I only have one, so it couldn't be that hard :slight_smile:

Thank you again to both you and @Bucking_horn !

Chuck

If you only have one interface then i believe you do not have to set this at all and should be fine. I set it as i have 3 nic and a rather complicated network setup that i need to restrict most things to certain interfaces.

Edit: forgot to mention... if you run other containers in addition to pihole you might want to give the pihole container priority over the other containers by setting --cpu-shares N as part of the run command. This will avoid other resource hungry containers like in my case plex, urbackup, tvheadend, etc from making the pihole container slow.

You are my hero. Are you running this on windows docker?

No I'm running this from a linux (Gentoo) host. As you are running on windows host your path references for the host will be different than mine.

Host mode networking does not work on Docker Desktop for Windows. I don't think you'll be able to use DHCP server for a Windows installation.

Windows runs the Docker setup on a hyper-v virtual machine with a separate network. DHCP is a broadcast technology and does not cross over in to other network segments. You might be able to set up a DHCP helper on your LAN and have it forward DHCP lease requests to the container in that hyper-v VM but I've never seen it done.

Thanks Dan, I guess I am throwing in the towel on this one. Perhaps running a non-containerized and concurrent PFSENSE firewall (that has DHCP serve capability) is the best way of achieving a DHCP server and getting some firewall capes at the same time. Do you have an opinion on this?

Thanks again

Chuck

I personally use OPNsense.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.