Networking & DNS

Run Pi-hole on Raspberry Pi with Docker Compose

If your Raspberry Pi already runs other services in Docker, you can run Pi-hole as a separate Docker Compose project. Its settings stay in their own folder, and the router keeps handing out IP addresses. Pi-hole only answers and filters DNS queries.

A router handles DHCP while a Pi-hole container on a Raspberry Pi answers DNS queries

If you prefer not to use Docker, follow the direct Pi-hole installation guide for Raspberry Pi OS. Pick one method per host because both need DNS port 53.

Check the IP address and ports

This example assumes 64-bit Raspberry Pi OS with Docker Engine and the Compose plugin installed. Reserve a LAN IP for the Pi on your router, such as 192.168.1.10. Check the addresses and ports in use on the Pi:

hostname -I
docker compose version
sudo ss -lntup '( sport = :53 or sport = :8080 )'
docker ps --format 'table {{.Names}}\t{{.Ports}}'

If something already uses port 53 on the Pi’s LAN address, identify it before changing anything. Don’t stop an existing DNS service just to get the install to run. If only port 8080 is taken, pick a free admin port such as 8082. The web port is flexible, but DNS settings on phones and routers normally use port 53.

Create the Compose files

Create a separate folder and a .env file inside it. Set the file permissions before entering a password.

mkdir -p ~/pihole
cd ~/pihole
touch .env
chmod 600 .env

Put the following in .env. Replace the IP with your Pi’s actual LAN address and the example password with your own long, randomly generated password. Keep the file out of Git.

PI_LAN_IP=192.168.1.10
PIHOLE_WEB_PORT=8080
PIHOLE_PASSWORD='replace-with-your-own-long-random-password'

Create compose.yaml in the same folder. This example pins official image release 2026.11.0 so readers use the same version. If you are following this later, check for a release with current security updates first.

services:
  pihole:
    image: pihole/pihole:2026.11.0
    ports:
      - "${PI_LAN_IP:?Set PI_LAN_IP}:53:53/tcp"
      - "${PI_LAN_IP:?Set PI_LAN_IP}:53:53/udp"
      - "${PI_LAN_IP:?Set PI_LAN_IP}:${PIHOLE_WEB_PORT:-8080}:80/tcp"
    environment:
      TZ: Asia/Bangkok
      FTLCONF_webserver_api_password: "${PIHOLE_PASSWORD:?Set PIHOLE_PASSWORD}"
      FTLCONF_dns_listeningMode: 'ALL'
    volumes:
      - './etc-pihole:/etc/pihole'
    restart: unless-stopped

The mount ./etc-pihole:/etc/pihole keeps the database and settings in a folder on the Pi, so they survive container replacement. The ALL listening mode is for Docker bridge networking as described in the Pi-hole Docker guide, not a reason to expose a public DNS resolver. The example binds the LAN address, but if a VPN or another network can route to that address, test access from those networks too. Do not forward the DNS or admin ports from the internet.

Keep DHCP on the router. This setup doesn’t need UDP port 67 or host networking. Leave the Pi’s own DNS settings alone for now so other services on that host can still resolve names if Pi-hole stops.

Start Pi-hole

docker compose config --quiet
docker compose up -d
docker compose ps

Open http://192.168.1.10:8080/admin/ from a device on your LAN, using the IP and port from .env, then enter the password you set. If the container doesn’t start, check docker compose logs --tail=60 pihole and check the ports again. There is no need to change the router to test this step.

Use Pi-hole to help block phishing sites

Besides ads and trackers, Pi-hole can block phishing and malware domains on its blocklists. You can also choose an upstream DNS provider that filters threats. When Pi-hole doesn’t block a query locally, it passes the query on for that provider to check.

  • Quad9 9.9.9.9 and 149.112.112.112: Blocks known phishing and malware domains. If a site you normally use stops opening, check the domain in Quad9’s lookup tool to see whether it was blocked and which list flagged it.
  • Cloudflare 1.1.1.2 and 1.0.0.2: Also blocks phishing and malware domains, but uses a different list. To filter adult sites as well, use 1.1.1.3 and 1.0.0.3 instead.

If phishing is your main concern, Quad9 is a good starting point. Pick one pair rather than mixing providers: Pi-hole can send queries to either server, and each may block different domains.

In Pi-hole’s admin page, go to Settings → DNS, select only the pair you want, and click Save. If the pair isn’t listed, enter the addresses under Custom DNS servers and clear the old selections. This changes where Pi-hole forwards queries. Your test computer should still point to the Pi’s IP address.

Both services filter by domain. A brand-new phishing site may not be listed yet, and DNS can’t single out a phishing page hosted alongside normal pages on the same domain.

Start Pi-hole and try one device

If you have dig on a computer on the LAN, query Pi-hole directly over UDP and TCP. Replace the example IP with your own.

dig @192.168.1.10 example.com A
dig @192.168.1.10 example.com A +tcp

If both queries show status: NOERROR and an A record in the ANSWER SECTION, note the existing DNS settings on one device. Point only that device at the Pi, and visit a site you haven’t opened in this test. Look in Query Log for new requests from that device. To check filtering, try a domain already on the blocklist and confirm its query shows as Blocked. A successful dig result proves Pi-hole answered that query, not that the browser or every app uses it.

If no requests show up, check for an IPv6 resolver or Secure DNS in the browser. On an iPhone or iPad with iCloud Private Relay on, Pi-hole’s default may make Private Relay unavailable on the test network. Check Safari separately rather than disabling device-wide privacy settings just to pass the test.

If you chose Quad9, you can query its documented test name without opening a harmful website. Replace the example IP with your Pi’s IP address.

dig @192.168.1.10 isitblocked.org A

Quad9’s example returns NXDOMAIN with AUTHORITY: 0. Check the Query Log to see that the upstream server blocked the query rather than a local Pi-hole list. An NXDOMAIN response alone can also mean the domain doesn’t exist.

Set the router DNS for the rest of the home

If the pilot works, record the router’s old settings before changing the DNS address its LAN DHCP service gives clients. Keep DHCP on the router and verify again after devices reconnect. If the router also advertises an IPv6 DNS resolver, check that setting separately. A public DNS server listed as a second option may let some queries bypass filtering.

Go back to the previous DNS settings

To stop the test, first restore the old DNS settings on the device or router, then run docker compose down from the same folder. This stops the Pi-hole stack without deleting etc-pihole. If the whole home relies on a single Pi-hole, websites may stop opening whenever the Pi or container is down, even if Wi-Fi is still connected.

EOF.← Back to articles