This guide walks you through installing Pi-hole, a network-wide ad blocker, on a Raspberry Pi using Docker. Running Pi-hole in Docker keeps the system clean, makes updates simple, and lets you roll back changes easily. Before you start, you’ll need a Raspberry Pi (any model from Pi 3 onward works well) with Raspberry Pi OS (32-bit or 64-bit) installed and connected to your network. You’ll also need a way to access the terminal—either directly with a monitor and keyboard or via SSH from another computer. Finally, make sure your Pi has a static IP address on your local network, because Pi-hole needs a fixed address to act as your DNS server.
What You’ll Need
- A Raspberry Pi (Pi 3, Pi 4, or Pi 5) running Raspberry Pi OS (Bookworm or later)
- Docker and Docker Compose installed on the Pi (we’ll cover this)
- A static IP address for your Pi (set in your router or on the Pi itself)
- Access to your router’s admin panel to change DNS settings
- An SSH client (like PuTTY or the terminal on macOS/Linux) if you’re not using a monitor
Step-by-Step
- Update your system. Open a terminal on your Pi (or SSH into it) and run:
sudo apt update && sudo apt upgrade -y. This ensures your system packages are current, which helps avoid compatibility issues with Docker. - Install Docker. The easiest way is to use the official convenience script. Run:
curl -fsSL https://get.docker.com -o get-docker.sh, thensudo sh get-docker.sh. This installs Docker Engine and the Docker CLI. After it finishes, add your user to thedockergroup so you don’t needsudofor every command:sudo usermod -aG docker $USER. Log out and back in (or runnewgrp docker) for the change to take effect. - Install Docker Compose plugin. Docker Compose v2 is included with the convenience script, but if it’s not available, install it with:
sudo apt install docker-compose-plugin. Verify withdocker compose version. - Create a directory for Pi-hole. Run
mkdir ~/pihole && cd ~/pihole. This keeps all Pi-hole files in one place, making backups and updates easier. - Create a docker-compose.yml file. Use a text editor (like
nano) to create a file nameddocker-compose.ymlin that directory. Paste the following configuration:services: pihole: container_name: pihole image: pihole/pihole:latest ports: - "53:53/tcp" - "53:53/udp" - "80:80/tcp" - "443:443/tcp" environment: TZ: 'America/New_York' # Change to your timezone WEBPASSWORD: 'your_secure_password' # Set a strong password volumes: - './etc-pihole:/etc/pihole' - './etc-dnsmasq.d:/etc/dnsmasq.d' restart: unless-stoppedReplace
America/New_Yorkwith your timezone (find yours at this list) and set a strong password for the web interface. - Start Pi-hole. Run
docker compose up -dfrom the~/piholedirectory. Docker will pull the Pi-hole image and start the container. Wait a minute or two for it to initialize. - Verify the container is running. Run
docker psto see the Pi-hole container listed with status “Up”. If it shows “Restarting” or “Exited”, check the logs withdocker logs piholefor errors. - Access the Pi-hole admin interface. Open a web browser on any device on your network and go to
http://<your_Pi_IP_address>/admin. You’ll see a login page—use the password you set in the compose file. - Set your Pi’s IP as the DNS server on your router. Log into your router’s admin panel (usually at
192.168.1.1or similar). Find the DHCP settings and change the DNS server to your Pi’s static IP address. Save the settings and reboot your router if needed. This makes all devices on your network use Pi-hole for DNS, which blocks ads network-wide. - Test the setup. On a device, try visiting a website with ads. You should see fewer ads. To confirm DNS is working, run
nslookup pi-hole.netfrom a computer—it should return your Pi’s IP address as the server.
Common Mistakes
- Not setting a static IP before starting. If your Pi’s IP changes, devices won’t be able to find Pi-hole, and you’ll lose internet on your network when the IP changes.
- Forgetting to open port 53 in the firewall. If you have a firewall enabled (like
ufw), you must allow DNS traffic:sudo ufw allow 53andsudo ufw allow 80(for the web interface). - Using the wrong timezone. The timezone in the compose file affects log timestamps and scheduling. If it’s wrong, you’ll see odd times in the dashboard.
- Not changing the default web password. The default password is “admin” if you don’t set one. That’s a security risk on any network.
- Running the container as root. The Pi-hole image runs as root by default, which is fine for a home network, but if you’re security-conscious, you can set
user: "1000:1000"in the compose file (but note this may cause permission issues with the web interface).
Tips
- Back up your configuration. The
etc-piholedirectory contains all your settings and lists. Copy it to another machine or a USB drive regularly. - Update Pi-hole easily. To update to the latest version, run
docker compose pulland thendocker compose up -d. This pulls the new image and recreates the container with your existing volumes. - Use a custom DNS upstream. By default, Pi-hole uses Google’s DNS (8.8.8.8). You can change this in the web interface under Settings → DNS. Consider using Cloudflare (1.1.1.1) or your ISP’s DNS for potentially faster resolution.
- Monitor logs. Use
docker logs piholeto see what’s happening. If you suspect issues, check the logs first. - Set a strong web password. Use a password manager to generate a random one, and store it securely.
Troubleshooting
- Container won’t start. Run
docker logs piholeto see the error. Common issues include port conflicts (another service using port 53 or 80) or incorrect volume permissions. If port 53 is in use, stop the conflicting service or change the port mapping (but then DNS won’t work on the default port). - Web interface not loading. Ensure the container is running and port 80 is mapped. Try
curl http://localhost/adminfrom the Pi. If it fails, check that no other web server (like Apache or nginx) is running:sudo systemctl stop apache2if needed. - Devices not using Pi-hole. Check your router’s DHCP settings—make sure the DNS server is set to your Pi’s IP, not the router’s own IP. Also, some devices (like Chromecast) use hardcoded DNS, so they won’t be filtered.
- DNS resolution is slow. This can happen if your Pi’s network connection is weak or if the upstream DNS is slow. Try changing the upstream DNS in the Pi-hole settings. Also, ensure your Pi is connected via Ethernet rather than Wi-Fi for better performance.
- After a reboot, Pi-hole doesn’t start. The
restart: unless-stoppedpolicy should handle this. If it doesn’t, check that Docker is enabled on boot:sudo systemctl enable docker.
Frequently Asked Questions
- Will Pi-hole slow down my internet? No, Pi-hole acts as a DNS server, which is a lightweight process. It typically makes your internet feel faster because it blocks ads and trackers before they load.
- Can I use Pi-hole on a Raspberry Pi Zero? Yes, but the Pi Zero’s limited RAM (512MB) can be tight. It works for small networks, but you may see slower response times. A Pi 3 or 4 is recommended.
- Do I need to change the DNS settings on each device? No, if you set the DNS on your router, all devices on your network will automatically use Pi-hole. However, some devices (like phones on cellular) won’t be affected.
- Can I run Pi-hole alongside other Docker containers? Yes, Docker allows multiple containers. Just make sure you don’t have port conflicts. For example, if you run a web server on port 80, you’ll need to change Pi-hole’s web port.
- How do I uninstall Pi-hole? Run
docker compose downfrom the~/piholedirectory. To remove the volumes and all data, add-vto the command. Then delete the~/piholedirectory. - Is it safe to run Pi-hole as root? For a home network, it’s generally acceptable. If you’re concerned, you can run the container with a non-root user by adding
user: "1000:1000"to the compose file, but you may need to adjust volume permissions.