Pi-hole container not starting after host reboot

Hi Everybody!

When I reboot the host on which my Pi-hole container is running, the Pi-hole container does not automatically start, instead it is in exited state. But if I start the Pi-hole container manually afterwards, then it starts up fine. The container has a restart polify of always, but that does not seem to help.

This is what I see in the logs of the Pi-hole container:

s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service _postFTL: stopping
s6-rc: info: service _postFTL successfully stopped
s6-rc: info: service lighttpd: stopping
Stopping lighttpd
s6-rc: info: service lighttpd successfully stopped
s6-rc: info: service pihole-FTL: stopping
Stopping pihole-FTL
s6-rc: info: service pihole-FTL successfully stopped
s6-rc: info: service _startup: stopping
s6-rc: info: service _startup successfully stopped
s6-rc: info: service _uid-gid-changer: stopping
s6-rc: info: service _uid-gid-changer successfully stopped
s6-rc: info: service cron: stopping
Stopping cron
s6-rc: info: service cron successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

My Docker compose file for Pi-hole looks like this:

services:
  pihole:
    container_name: pi-hole
    image: pihole/pihole:latest
    restart: always
    # For DHCP it is recommended to remove these ports and instead add: network_mode: "host"
    ports:
      - "192.168.0.128:53:53/tcp" # DNS TCP port - important to bind to the IP of the host, otherwise DNS resolution won't work in Docker containers
      - "192.168.0.128:53:53/udp" # DNS UDP port - important to bind to the IP of the host, otherwise DNS resolution won't work in Docker containers
      # - "67:67/udp" # Only required if you are using Pi-hole as your DHCP server
      - "8001:80/tcp" # HTTP port

    environment:
      WEBPASSWORD: '<PI_HOLE_PASSWORD>'
      DNSMASQ_LISTENING: all
    volumes:
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
      - pihole-etc:/etc/pihole
      - pihole-etc-dnsmasq.d:/etc/dnsmasq.d

volumes:
  pihole-etc:
    name: pihole-etc
  pihole-etc-dnsmasq.d:
    name: pihole-etc-dnsmasq.d

I was able to narrow down the problem to the following DNS port mappings in the Docker compose file:

    ports:
      - "192.168.0.128:53:53/tcp"
      - "192.168.0.128:53:53/udp"

If I change it to the following, then it works well (Pi-hole container starts fine after reboot):

    ports:
      - "53:53/tcp"
      - "53:53/udp"

Note that 192.168.0.128 there is the local IP address of the host on which the Pi-hole container is running.

The problem is, unfortunately, that I DO need to map the DNS port 53 in the original form (using the host IP address in the mapping), otherwise DNS resolving does not work in any other containers which are defined in other Docker compose files. This is because I use Pi-hole as my DNS server.

I'm not sure why mapping the DNS port 53 using the host IP causes the PI-hole container not to start up, but I've noticed that very rarely it works even with this mapping (maybe 1 out of 10 times), so I guess that mapping using the host IP address introduces some kind of dependency which is usually not yet available when the Pi-hole container is starting.

Not sure how to solve this to have the Pi-hole container starting automatically after the host reboot, but also to have working DNS resolving in other containers.

I've struggled for many hours to find alternative solutions to get the DNS resolving working in other containers, but was not able to find any other good solution . For example using network_mode: host in the Pi-hole container also solves the DNS resolving in other containers, but it completely breaks the ad blocking.

Thank you for any advice you may be able to give me on this.

Hello there.

I’ve had this issue before.

You may want to take a look at this thread where I posted a solution

1 Like

Wow, man! This actually works. Thank you very much!

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