Pi-hole is a network-wide ad blocker that works at the DNS layer. Instead of installing an extension in every browser, you point your router or devices at one small server and every request for an advertising domain is dropped before it leaves your network. Running Pi-hole in Docker makes deployment reproducible and upgrades painless, while keeping configuration and statistics in a few host files. This guide covers a practical Compose stack, DHCP choices, upstream resolvers, security, and backups.

How Pi-hole Blocks Ads

When a device wants to load a page, it asks a DNS resolver to translate a domain into an IP address. Pi-hole keeps a list of known advertising and tracking domains and answers those requests with nothing, so the ad never loads. Because the filtering happens for every device that uses Pi-hole as its resolver, it covers phones, smart TVs, and applications that cannot run browser extensions. It also gives you a quieter network and a useful log of which domains your devices contact.

Pi-hole is not a firewall and it does not inspect encrypted traffic. It simply refuses to resolve domains on its blocklists. That distinction matters: some apps hardcode an IP address and bypass DNS entirely, and some advertising is served from the same domain as the content you want. For those cases, Pi-hole helps but cannot block everything.

Prerequisites

You need a Linux host with a static IP address, Docker and Docker Compose, and about 1 GB of RAM at most. A wired connection is preferable because every device on your network will depend on this resolver. If Docker is new to you, the Docker basics for homelab guide explains the concepts used here. A reverse proxy with HTTPS is optional but useful if you want to reach the admin dashboard from outside your home network.

Docker Compose Deployment

Create /opt/pihole with subdirectories etc-pihole and etc-dnsmasq.d, then save this stack as docker-compose.yml:

services:
  pihole:
    image: pihole/pihole:6.0
    container_name: pihole
    restart: unless-stopped
    environment:
      TZ: Asia/Ho_Chi_Minh
      WEBPASSWORD: ${PIHOLE_PASSWORD}
      DNSMASQ_LISTENING: all
      FTLCONF_dns_upstreams: 1.1.1.1;8.8.8.8
    volumes:
      - ./etc-pihole:/etc/pihole
      - ./etc-dnsmasq.d:/etc/dnsmasq.d
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "80:80/tcp"
    cap_add:
      - NET_ADMIN
    healthcheck:
      test: ["CMD", "dig", "+short", "pi.hole", "localhost"]
      interval: 30s
      timeout: 5s
      retries: 3

Set a strong admin password in .env:

PIHOLE_PASSWORD=***

Start the stack with docker compose up -d, then visit http://<host-ip>/admin and log in. The two bind mounts hold your blocklists, settings, and statistics, so recreating the container does not lose your configuration. The FTLCONF_dns_upstreams variable chooses the resolvers Pi-hole forwards non-blocked queries to; adjust those addresses if you prefer a different provider or run your own validating resolver.

The NET_ADMIN capability is needed for Pi-hole’s DHCP server. If you do not plan to use Pi-hole for DHCP, remove that capability to keep the container more restricted.

Pointing Devices at Pi-hole

The simplest method is to set your router’s DNS server to the Pi-hole host IP. Most routers have a DHCP settings page where you can specify a DNS server; after a lease renewal, all clients will use Pi-hole automatically. If your firmware does not allow this, configure DNS manually on individual devices.

Avoid pointing Pi-hole at itself for upstream DNS, and do not use your ISP’s resolver if you want an independent view of tracking domains. Verify the setup from another machine with dig google.com @<pihole-ip>; the reply should come through your Pi-hole. Visit a known advertising test page and watch the Pi-hole dashboard for blocked queries.

DHCP and Local DNS

Pi-hole can also act as a DHCP server. This gives you per-client statistics and lets Pi-hole resolve local host names. To enable it, turn off DHCP on your router first, then enable DHCP in the Pi-hole admin interface under Settings. Only one DHCP server should be active on a network; two competing servers cause confusing lease conflicts.

For local names, add entries under Local DNS in the dashboard. Services such as a Caddy reverse proxy or a NAS can then be reached by friendly names instead of raw IPs.

Security and Privacy

The admin dashboard should never be exposed publicly. Keep it on your LAN, or put it behind an authenticated HTTPS reverse proxy and require a VPN for remote access. Change WEBPASSWORD from the default, and keep the .env file out of git. Because Pi-hole sees every DNS query on your network, it is a privacy-sensitive service: restrict who can read its logs, and consider reducing the log retention period in the settings if you do not need long-term statistics.

Keep the image pinned to a specific version. Before upgrading, take a backup, then change the tag and recreate the container. Most upgrades only replace the application code because all state lives in the two bind mounts.

Backups and Monitoring

Back up etc-pihole and etc-dnsmasq.d together. A nightly tar archive copied off the host is enough for a home network. The Docker volume backup guide describes a reusable script, and the Restic backup guide shows how to encrypt archives and send them offsite. Restore at least once on a test container so you know the archive contains what you expect.

If you already run Uptime Kuma, add a DNS check for a normal domain and a blocked domain. A failure of the normal query means Pi-hole or its upstream is down; a successful answer for a blocked domain means your blocklist stopped working. The built-in dashboard also shows query volume, blocked percentage, and the top clients.

Common Mistakes

The usual problem is setting Pi-hole as the resolver but leaving a second DNS server on clients, which lets devices bypass filtering. Another is enabling DHCP on both the router and Pi-hole. Using your router as the upstream resolver can create a loop, so pick a public or dedicated upstream instead. Finally, forget to back up the two configuration directories and you lose years of custom rules.

FAQ

Does Pi-hole slow down browsing? Usually no. Queries are answered locally or forwarded to a nearby resolver, and blocked queries are faster than normal ones.

Will Pi-hole block all ads? No. It blocks domains on its lists, so ads served from the same domain as the site remain. Browser extensions still complement it.

Can I use Pi-hole away from home? Only if you set up a VPN or an authenticated HTTPS proxy. Do not publish the admin interface directly.

How often should blocklists update? Pi-hole updates lists on a schedule automatically. Weekly is a reasonable default for a home network.

Can Pi-hole replace my router’s DHCP? Yes, but disable DHCP on the router first and enable only one DHCP server on the network.

Pi-hole in Docker is one of the highest-value homelab projects: a small container that quietly improves privacy and reduces noise for every device on your network. Start with the Compose file above, keep the dashboard private, and make backups a habit.