Issues Setting up Docker Pi-hole DHCP with Host Networking Mode

Expected Behaviour:

I am attempting to set up Pi-hole with DHCP since my router (AT&T) doesn't allow setting DNS manually.
I am running Pi-hole through Docker on a 2020 Intel MacBook Pro that runs constantly.
I assigned a static IP (192.168.1.66) to the device through my router portal and the same one in my device's WiFi settings.

Here is my initial docker-compose.yml (before DHCP):

services:
  pihole:
    container_name: pihole
    image: pihole/pihole:latest
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "80:80/tcp"
    environment:
      TZ: 'America/Chicago'
      WEBPASSWORD: '######'
    volumes:
      - './etc-pihole:/etc/pihole'
      - './etc-dnsmasq.d:/etc/dnsmasq.d'
    restart: unless-stopped

This seemed to work correctly and the UI was accessible over my local network.
I then updated the yml file to enable DHCP:

services:
  pihole:
    container_name: pihole
    image: pihole/pihole:latest
    network_mode: "host"
    environment:
      TZ: 'America/Chicago'
      WEBPASSWORD: '######'
    volumes:
      - './etc-pihole:/etc/pihole'
      - './etc-dnsmasq.d:/etc/dnsmasq.d'
    cap_add:
      - NET_ADMIN
    restart: unless-stopped

After these changes, I disabled DHCP on my router, restarted it, and ran docker compose on my laptop.
Next, I tried accessing the Pi-hole UI to set up the DHCP configuration.

Actual Behaviour:

I am no longer able to access the UI at http://127.0.0.1/admin/login.php
Some of my devices (dynamic IP) are able to acquire an IP.

Logs:

Here is some of the log output.
The last 2 lines repeat many more times.

Jun 14 12:25:03 dnsmasq[258]: compile time options: IPv6 GNU-getopt no-DBus no-UBus no-i18n IDN DHCP DHCPv6 Lua TFTP no-conntrack ipset no-nftset auth cryptohash DNSSEC loop-detect inotify dumpfile
Jun 14 12:25:03 dnsmasq-dhcp[258]: DHCP, IP range 192.168.1.64 -- 192.168.1.253, lease time 1d
Jun 14 12:25:03 dnsmasq[258]: using nameserver 8.8.8.8#53
Jun 14 12:25:03 dnsmasq[258]: using nameserver 8.8.4.4#53
Jun 14 12:25:03 dnsmasq[258]: using only locally-known addresses for onion
Jun 14 12:25:03 dnsmasq[258]: using only locally-known addresses for bind
Jun 14 12:25:03 dnsmasq[258]: using only locally-known addresses for invalid
Jun 14 12:25:03 dnsmasq[258]: using only locally-known addresses for localhost
Jun 14 12:25:03 dnsmasq[258]: using only locally-known addresses for test
Jun 14 12:25:03 dnsmasq[258]: read /etc/hosts - 8 names
Jun 14 12:25:03 dnsmasq[258]: read /etc/pihole/custom.list - 0 names
Jun 14 12:25:03 dnsmasq[258]: read /etc/pihole/local.list - 0 names
Jun 14 12:25:05 dnsmasq[258]: read /etc/hosts - 8 names
Jun 14 12:25:05 dnsmasq[258]: read /etc/pihole/custom.list - 0 names
Jun 14 12:25:05 dnsmasq[258]: read /etc/pihole/local.list - 0 names
Jun 14 12:25:32 dnsmasq[258]: query[A] pi.hole from 127.0.0.1
Jun 14 12:25:32 dnsmasq[258]: Pi-hole hostname pi.hole is 0.0.0.0

Host network mode is not available for Docker Desktop (Windows or MacOS), unless you are using a very recent version and manually enable this feature.

From Docker docs page: Networking using the host network | Docker Docs :

The host networking driver only works on Linux hosts, but is availabe as a beta feature on Docker Desktop version 4.29 and later for Mac, Windows, and Linux. To enable this feature, navigate to the Features in development tab in Settings, and then select Enable host networking.

1 Like

Ok, thank you for this. I was unaware this was the case. Would you recommend using another networking mode mentioned on the pi-hole documentation page (DHCP), using the container in a Linux VM (mentioned here), running the beta version of Docker that supports host networking, or some combination of the above?

About the options you asked:

  • VM:
    there is no reason to run docker inside a VM. Install Pi-hole directly on the VM OS.

  • Docker Desktop:
    I don't have personal experience with Docker Desktop. I usually don't use it. It's a lot easier to run docker in Linux, specially if you want to use a different network mode.
    If you really want to use it, you don't need to install a beta version of docker to enable Host mode. You just need a recent version. This should be in Settings > Features in development.

1 Like

Install Pi-hole directly on the VM OS

Ah, yes that makes sense.

This should be in Settings > Features in development

I'll try this first since it should be a smaller change from the current configuration.
If it doesn't work, I'll go with the VM.

Thanks for your help.
I'll respond back I have any other related questions.

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