
Docker Compose turned my fragile Pi-hole setup into a rock-solid DNS fortress - How-To Geek
Technology writer Umair Khurshid has successfully transformed his fragile Pi-hole DNS setup into a rock-solid system using Docker Compose, providing easier recovery and management.
Pi-hole is a home lab service that blocks ads and trackers while handling DNS queries, often working silently in the background until something breaks. When DNS functionality fails, websites can appear offline even with a perfectly functional internet connection. Technology writer Umair Khurshid has developed a solution using Docker Compose to make his Pi-hole setup more resilient and easier to recover when issues occur.
Reliable foundation
The problem with fragile setups is that everything appears fine until changes are needed, such as container updates, host reboots, or accidental deletions. Docker Compose provides a single file describing how Pi-hole runs, which ports it uses, and where its configuration lives, eliminating the need to reconstruct details from memory when recreating the service.
Pi-hole handles DNS over TCP and UDP port 53, while the web interface is accessed through port 8080. The Compose configuration maps the external port to port 80 inside the container, where Pi-hole v6's embedded web server listens by default. The configuration includes persistent bind mounts, keeping Pi-hole's configuration on the host at /opt/pihole/etc-pihole rather than only inside the container.
Do not copy this file unchanged. The image tag, password, and LAN address must match your environment, and the persistent directory must exist before starting the container.
Persistent storage
The restart: unless-stopped policy helps when Docker starts after a host reboot or restarts the container after an unexpected exit. Docker's system service is enabled to start at boot. The bind mount and restart policy solve different problems - restarting helps when processes exit unexpectedly, while persistent storage means containers can be recreated without deleting saved settings.