How to Run Pi-hole in Docker (Complete Guide)

How to Run Pi-hole in Docker (Complete Guide)

How to Run Pi-hole in Docker (DNS Ad Blocking with Docker Compose)

If you are already running Docker on your server, putting Pi-hole in a container is the obvious choice. Your DNS service gets the same isolation, portability, and reproducibility as every other service in your stack. You can version control the compose file, blow away the container without affecting your host, and redeploy the whole thing in sixty seconds if something goes wrong.

From the homelab: Pi-hole was one of the first services I self-hosted, and it is still running. There is something satisfying about watching the query log and seeing how many ad and tracking domains get blocked across your network. It is also a brilliant introduction to DNS if you have never managed it before.

I run Pi-hole in Docker on my homelab alongside a dozen other services. It has been rock solid for over a year. But there is one specific gotcha with the Docker deployment that trips up nearly everyone, and it is not the one you are expecting. It is not Docker itself. It is the port 53 conflict with systemd-resolved on Ubuntu, combined with the networking mode question that Docker introduces. Get those two things right and the rest is straightforward.

This guide assumes you have Docker and Docker Compose already installed. If not, follow the Docker installation guide for Ubuntu 24.04 first. If you would rather install Pi-hole natively without Docker, see the Pi-hole on Ubuntu 24.04 guide instead.

The short answer. On a stock Ubuntu Server, Pi-hole’s container cannot start until systemd-resolved stops holding port 53: set DNSStubListener=no, relink /etc/resolv.conf, then restart systemd-resolved and Docker. After that, use the Compose file below with a pinned image tag, run docker compose up -d, and test with dig @127.0.0.1 ads.google.com, which should answer 0.0.0.0. If you already ran docker compose up -d before the fix, run docker compose down first: the container from the failed attempt has no working DNS.

Tested on: Ubuntu Server 24.04.5 LTS (cloud image), Docker Engine from the 29 series with Compose from the v5 series, from Docker’s apt repository (exact point releases were not recorded for this run), pihole/pihole:2026.11.0 (Pi-hole Core v6.6, Web v6.6.1, FTL v6.9). Lab run on 15 November 2026. Where this guide quotes an error or a screen, it came from that run.

Prerequisites

  • Docker and Docker Compose installed (installation guide)
  • Ubuntu 24.04 or 26.04 LTS or similar Linux host with a static IP address
  • SSH access to your server
  • Router access for DNS configuration later

The Port 53 Problem (Read This Before Anything Else)

If you are running Ubuntu, you will hit this. It is the single most common reason Pi-hole fails to start in Docker, and I have seen experienced engineers waste an hour on it because they assumed it was a Docker networking issue when it was actually an Ubuntu default.

Ubuntu runs systemd-resolved, a local DNS stub resolver that listens on port 53. Pi-hole also needs port 53. Docker will try to bind the container’s port 53 to the host’s port 53 and fail because systemd-resolved is already there.

The error looks like this on Docker Engine 29:

Error response from daemon: failed to set up container networking: driver failed programming
external connectivity on endpoint pihole (...): failed to bind host port 0.0.0.0:53/tcp: address already in use
On stock Ubuntu Server 24.04, ss shows systemd-resolve on 127.0.0.53 and 127.0.0.54 port 53, and docker compose up -d fails: failed to bind host port 0.0.0.0:53/tcp, address already in use
On stock Ubuntu Server 24.04, ss shows systemd-resolve on 127.0.0.53 and 127.0.0.54 port 53, and docker compose up -d fails: failed to bind host port 0.0.0.0:53/tcp, address already in use.

Other Docker versions word it differently (look for bind, 53 and either address already in use or port is already allocated). The cause is the same.

Here is the fix:

# Check if port 53 is in use (a stock 24.04 install shows two listeners,
# 127.0.0.53 and 127.0.0.54, both owned by systemd-resolve)
sudo ss -lntp | grep ':53 '

# Edit resolved config
sudo nano /etc/systemd/resolved.conf

Set these values under [Resolve]:

[Resolve]
DNSStubListener=no
DNS=1.1.1.1
FallbackDNS=8.8.8.8

Then fix the resolv.conf symlink and restart:

sudo rm /etc/resolv.conf
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
sudo systemctl restart systemd-resolved

# Verify port 53 is free
sudo ss -lntp | grep ':53 '

# Restart Docker so it stops using the old 127.0.0.53 resolver
sudo systemctl restart docker

The ss check should return nothing. Now Docker can bind to port 53. The DNSStubListener setting is described in the resolved.conf manual page.

The fix: DNSStubListener=no in resolved.conf, resolv.conf pointed at the real resolver file, systemd-resolved restarted, 'port 53 is free', then Docker restarted
The fix: DNSStubListener=no in resolved.conf, resolv.conf pointed at the real resolver file, systemd-resolved restarted, 'port 53 is free', then Docker restarted.

Do not skip the Docker restart. In the lab run behind our Pi-hole vs AdGuard Home comparison, the next image pull failed with lookup registry-1.docker.io on 127.0.0.53:53 ... connection refused until the Docker service was restarted. The restart also restarts the other containers on the host, so pick a quiet moment.

Do not skip the resolv.conf symlink step. If you only change the config and restart systemd-resolved, your server will still point at 127.0.0.53 for its own DNS lookups. That address no longer works because you disabled the stub listener. Your server will not be able to resolve any domains, including pulling Docker images. I have made this mistake more than once. It is infuriating.

Host Network vs Bridge Network: The Docker Networking Decision

This is the gotcha specific to running Pi-hole in Docker, and it is worth understanding properly because it affects how your query logs work.

Pi-hole in Docker network modes compared: bridge, host and macvlan, what Pi-hole sees and the trade-off of each
Bridge, host and macvlan side by side, with this guide's recommendation in the last row.

Bridge network (default)

With a bridge network and published ports on a normal Linux Docker host, IPv4 queries from your LAN are passed to the container by NAT, so Pi-hole usually still sees each device’s real IP. The exception is any query that reaches the container through Docker’s userland proxy instead: for example IPv6 queries to an IPv4-only bridge network, or Docker Desktop. Those show up as the Docker gateway address (typically 172.x.0.1), so your dashboard shows one client making thousands of queries and you lose per-device visibility for that traffic. Bridge mode also cannot serve DHCP to your LAN without a DHCP relay.

Host network

With network_mode: host, the container shares the host’s network stack directly. Pi-hole sees the real source IP of every query. Your dashboard shows individual devices, and group management works properly because you can assign rules per client.

Bridge network with macvlan

A macvlan network gives the container its own IP address on your LAN, separate from the host. Pi-hole sees real client IPs, and you get network isolation. This is the most complex to set up but the cleanest from a networking perspective.

My recommendation: Use bridge networking with explicit port mappings. Yes, you can lose per-device client identification in some configurations, but it is the most portable, easiest to debug, and works reliably across different Docker versions. If per-client visibility matters to you (and it should, once you start using group management), switch to host networking. Avoid macvlan unless you already understand Docker networking well.

Docker Compose Setup

Create a directory for your Pi-hole deployment:

mkdir -p ~/services/pihole && cd ~/services/pihole

Create the environment file first. Never hardcode passwords in your compose file:

cat > .env << 'EOF'
PIHOLE_PASSWORD=your-secure-admin-password
PIHOLE_DNS=1.1.1.1;9.9.9.9
TZ=Europe/London
EOF

Now create docker-compose.yml. This is for the Pi-hole v6 image (every pihole/pihole tag after 2024.07.0), which is what you get when you pull today:

services:
  pihole:
    container_name: pihole
    image: pihole/pihole:2026.11.0   # or :latest; see "Updating" below
    restart: unless-stopped
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "8081:80/tcp"     # web admin over HTTP (8080 is UniFi's inform port)
      - "8444:443/tcp"    # web admin over HTTPS, self-signed (8443 is UniFi's UI port)
    environment:
      TZ: ${TZ}
      FTLCONF_webserver_api_password: ${PIHOLE_PASSWORD}
      FTLCONF_dns_upstreams: ${PIHOLE_DNS}
      FTLCONF_dns_listeningMode: 'ALL'   # needed on a bridge network
    volumes:
      - ./etc-pihole:/etc/pihole
    cap_add:
      - NET_ADMIN   # only needed if Pi-hole will be your DHCP server
      - SYS_NICE
The .env file and the Compose file from this guide: image pihole/pihole:2026.11.0, ports 53, 8081 and 8444, the FTLCONF_ variables and the etc-pihole bind mount
The .env file and the Compose file from this guide: image pihole/pihole:2026.11.0, ports 53, 8081 and 8444, the FTLCONF_ variables and the etc-pihole bind mount.

Copying an older compose file? The v5 variables are ignored in v6. Pi-hole v6 (February 2025) replaced nearly every environment variable with an FTLCONF_ equivalent. If your file still uses the old names, the container starts but your settings silently do not apply: you get a random admin password (printed in docker logs pihole) and default upstreams. The common ones:

  • WEBPASSWORD is now FTLCONF_webserver_api_password
  • PIHOLE_DNS_ is now FTLCONF_dns_upstreams (separate servers with ;)
  • DNSMASQ_LISTENING is now FTLCONF_dns_listeningMode
  • WEB_PORT is now FTLCONF_webserver_port
  • FTLCONF_LOCAL_IPV4, ServerIP, DNS1/DNS2 and VIRTUAL_HOST are gone; delete them

Settings you set through FTLCONF_ variables become read-only in the web interface. That is deliberate: the compose file is the single source of truth. The full map is in the official v5 to v6 upgrade notes.

Settings, DNS: the upstream servers come from PIHOLE_DNS in .env, with Quad9 and Cloudflare ticked and a padlock beside the heading; the footer shows Docker tag 2026.11.0
Settings, DNS: the upstream servers come from PIHOLE_DNS in .env, with Quad9 and Cloudflare ticked and a padlock beside the heading; the footer shows Docker tag 2026.11.0.

Why port 8081 and not port 80? If you are running other web services behind a reverse proxy (Nginx Proxy Manager, Caddy, Traefik), they need port 80. Mapping Pi-hole's web interface to 8081 avoids the conflict, and also stays clear of 8080 and 8443, which the UniFi Network controller uses if you run it on the same box. You can always put Pi-hole's admin behind your reverse proxy later if you want a proper domain name for it. Plan your port allocations before you have six services fighting over port 80.

Host network alternative

If you want per-device visibility in the query logs, use host networking instead:

services:
  pihole:
    container_name: pihole
    image: pihole/pihole:latest
    restart: unless-stopped
    network_mode: host
    environment:
      TZ: ${TZ}
      FTLCONF_webserver_api_password: ${PIHOLE_PASSWORD}
      FTLCONF_dns_upstreams: ${PIHOLE_DNS}
      FTLCONF_webserver_port: '8081,8444s'
      FTLCONF_dns_listeningMode: 'LOCAL'
    volumes:
      - ./etc-pihole:/etc/pihole
    cap_add:
      - NET_ADMIN
      - SYS_NICE

Note the differences: no ports section (host networking exposes everything directly), FTLCONF_webserver_port set to 8081,8444s so Pi-hole’s built-in web server stays off ports 80 and 443 (by default v6 tries 80 and 443), and also off 8080 and 8443, which the UniFi Network controller uses if it shares the host, and FTLCONF_dns_listeningMode set to LOCAL rather than ALL, so Pi-hole only answers devices on subnets the host is directly attached to.

Start Pi-hole and Verify

# Start the container
docker compose up -d

# Check it is running
docker compose ps

# Test DNS resolution
dig @127.0.0.1 google.com

# Test blocking is working
dig @127.0.0.1 ads.google.com
# Should return 0.0.0.0

# Check container logs if something is wrong
docker compose logs pihole
docker compose up -d after the fix, then docker compose ps: the container is up and its health check is still starting
docker compose up -d after the fix, then docker compose ps: the container is up and its health check is still starting.
dig against Pi-hole on 127.0.0.1: google.com resolves, and ads.google.com is answered 0.0.0.0 with the extended error 'Blocked (gravity)'
dig against Pi-hole on 127.0.0.1: google.com resolves, and ads.google.com is answered 0.0.0.0 with the extended error 'Blocked (gravity)'.

Access the web interface at http://YOUR-SERVER-IP:8081/admin and log in with the password from your .env file.

The Pi-hole dashboard after a burst of test lookups: 33 queries, 10 blocked, 76,105 domains on the default list
The Pi-hole dashboard after a burst of test lookups: 33 queries, 10 blocked, 76,105 domains on the default list.

A healthy start ends with FTL running as the unprivileged pihole user and the web server listening on its two ports:

The end of a healthy start in docker compose logs: FTL running as user pihole, blocking enabled, web server on ports 80 and 443; pihole -v reports Core v6.6, Web v6.6.1 and FTL v6.9, all current
The end of a healthy start in docker compose logs: FTL running as user pihole, blocking enabled, web server on ports 80 and 443; pihole -v reports Core v6.6, Web v6.6.1 and FTL v6.9, all current.

If you ran docker compose up -d before fixing port 53

If you hit the error first, the failed attempt left a container behind, created while the host still pointed at the stub resolver. After the fix, a plain docker compose up -d starts that old container, and in the lab it came up with no working DNS of its own: the log says DNS resolution is currently unavailable, and docker exec pihole pihole -v reports Could not resolve host: github.com. Pi-hole could not even download its blocklist.

The container left over from the failed first attempt starts but cannot resolve names: the log ends 'DNS resolution is currently unavailable' and pihole -v cannot resolve github.com
The container left over from the failed first attempt starts but cannot resolve names: the log ends 'DNS resolution is currently unavailable' and pihole -v cannot resolve github.com.

Take the stack down and bring it up again, which creates a fresh container with the host’s current resolver settings:

docker compose down
docker compose up -d
docker compose ps
docker compose down, then up -d, then ps: the recreated container publishes ports 53, 8081 and 8444 and picks up the host's new resolver settings
docker compose down, then up -d, then ps: the recreated container publishes ports 53, 8081 and 8444 and picks up the host's new resolver settings.

Your etc-pihole folder is a bind mount on the host, so docker compose down leaves your settings in place.

Persistent Volumes: What Gets Saved and Why

The volume mount in the compose file is critical:

  • ./etc-pihole -- Contains pihole.toml (every v6 setting, including local DNS records and DHCP), the Gravity database (your lists, allow and deny entries, groups and clients) and the query database. This is all your customisation.
The etc-pihole bind mount after first start: pihole.toml, gravity.db, pihole-FTL.db and the TLS files all live outside the container
The etc-pihole bind mount after first start: pihole.toml, gravity.db, pihole-FTL.db and the TLS files all live outside the container.

Pi-hole v6 no longer reads /etc/dnsmasq.d by default, so a fresh install does not need that second volume. If you are migrating from v5 and had custom files there, mount it for the first v6 start so they can be migrated, and set FTLCONF_misc_etc_dnsmasq_d: 'true' if you still want Pi-hole to read them.

This volume means you can destroy and recreate the container without losing anything. Your lists, allow and deny entries, custom DNS records, and settings all survive. The container is disposable. The data is not.

# Pulling a new image and recreating preserves all data
docker compose pull
docker compose up -d

This is the correct update procedure. Do not docker compose down and delete the volumes unless you genuinely want to start fresh.

Custom DNS Records

One of Pi-hole's most useful features for a homelab is custom local DNS records. Instead of remembering IP addresses for all your services, you can create DNS entries that resolve on your local network.

In the web interface, go to Settings > Local DNS Records and add entries like:

pihole.home.lan    198.51.100.50
nextcloud.home.lan 198.51.100.50
grafana.home.lan   198.51.100.50

(198.51.100.50 is a documentation address standing in for your server’s own IP, which is what these records should point at.)

Pi-hole's Local DNS Records page listing the three records set above (the lab's password was cleared, so the page opens without a login)
Pi-hole's Local DNS Records page listing the three records set above (the lab's password was cleared, so the page opens without a login).

The same records can be set from the command line, which is handy when you build the container from a script:

docker exec pihole pihole-FTL --config dns.hosts '["198.51.100.50 pihole.home.lan", "198.51.100.50 nextcloud.home.lan", "198.51.100.50 grafana.home.lan"]'
dig +short @127.0.0.1 nextcloud.home.lan
Three local DNS records set with pihole-FTL --config dns.hosts, and a lookup of nextcloud.home.lan that returns the address
Three local DNS records set with pihole-FTL --config dns.hosts, and a lookup of nextcloud.home.lan that returns the address.

These records only resolve on your local network through Pi-hole. They do not need to be registered with any domain registrar. Any device using Pi-hole for DNS will resolve them.

You can also add CNAME records on the same page if you want aliases pointing to an existing DNS name rather than an IP.

Pick a local domain and stick with it. I use .home.lan for local services. Some people use .local, but that can conflict with mDNS/Bonjour on Apple devices. Others use a subdomain of a domain they own (e.g., lab.yourdomain.com). Whatever you pick, be consistent. Changing your local DNS naming scheme once you have twenty services configured is the kind of task you put off indefinitely.

Running Pi-hole Alongside Other Containers

If you are running Pi-hole on the same Docker host as other services, there are two things to be aware of.

Other containers resolving DNS: By default, Docker containers use Docker's embedded DNS server, not the host's DNS. Your other containers will not automatically use Pi-hole for their DNS queries. If you want them to, add DNS settings to their compose files:

services:
  some-other-service:
    image: whatever:latest
    dns:
      - 198.51.100.50  # Your Pi-hole IP (documentation address; use your own)

Port conflicts: If another container is already using port 53 (unlikely but possible with some DNS or VPN containers), Pi-hole will fail to start. Check for conflicts with docker ps and look at the ports column.

Resource usage: Pi-hole is lightweight. It typically uses 50-100 MB of RAM and negligible CPU. It will happily coexist with a dozen other services on modest hardware, including the five core containers every homelab should run. DNS queries are tiny and fast. You do not need to worry about Pi-hole competing with your other containers for resources.

Monitoring: once the whole house resolves through Pi-hole, a stopped container means nobody can load anything. Add a DNS monitor that resolves a known name through Pi-hole’s IP, so you hear about it before the family does; the Uptime Kuma Docker guide covers the DNS monitor type.

Configuring Your Router

Same as any Pi-hole deployment: you need to point your network's DNS at the Pi-hole server. The best approach is changing the DNS server in your router's DHCP settings so every device automatically uses Pi-hole. If your router does not support that, change the router's own DNS settings. As a last resort, configure devices individually.

See the Ubuntu Pi-hole guide for detailed router configuration options. The process is identical regardless of whether Pi-hole is running natively or in Docker.

Test before you commit. Before changing your router's DNS settings, verify Pi-hole is responding correctly from another device on your network: dig @198.51.100.50 google.com (replace with your server's IP). If that works, you are safe to point your router at it. If it does not, debug the Docker container first. Changing router DNS to a non-functional server takes down your entire network's internet access.

Web Admin Password Management

If you need to change the web interface password after deployment:

# If the password is set by FTLCONF_webserver_api_password (as above):
# update PIHOLE_PASSWORD in .env, then recreate the container
docker compose up -d --force-recreate

# If you did not set the variable, change it inside the container (Pi-hole v6)
docker exec -it pihole pihole setpassword
PIHOLE_PASSWORD edited in .env, then docker compose up -d --force-recreate recreates the container with the new value (the lab set it empty here so the admin pages could be captured without a login)
PIHOLE_PASSWORD edited in .env, then docker compose up -d --force-recreate recreates the container with the new value (the lab set it empty here so the admin pages could be captured without a login).

In v6, a setting supplied by an FTLCONF_ variable is read-only, so pihole setpassword cannot override the password from your compose file. If you have forgotten the password entirely and cannot log in, the environment variable approach is the clean reset. (The old v5 command pihole -a -p no longer exists.)

Updating Pi-hole in Docker

This is one of Docker's genuine advantages over a native install. Updates are clean and reversible:

cd ~/services/pihole

# Pull the latest image
docker compose pull

# Recreate with new image (data volumes preserved)
docker compose up -d

# Verify
docker compose ps
docker compose logs --tail 20 pihole
The update flow: docker compose pull, up -d (the container is already running the pinned tag), ps showing healthy, and the last 20 log lines
The update flow: docker compose pull, up -d (the container is already running the pinned tag), ps showing healthy, and the last 20 log lines.

With a pinned tag, docker compose pull only re-checks that tag, so nothing changes until you edit the version in docker-compose.yml yourself. The release page is github.com/pi-hole/docker-pi-hole/releases. On 15 November 2026 its newest tag was 2026.11.0, published on 11 November, which ships Pi-hole Core v6.6 and FTL v6.9 and whose notes say it fixes 11 security advisories. The older 2026.09.0 tag, which this guide pinned before today, carries FTL v6.7.1. Inside the container, pihole -up is disabled: the Pi-hole Docker docs say to upgrade by replacing the container with a newer image.

One warning: 2024.07.0 was the last v5 image. Rolling back across the v5 to v6 line is not supported, because the first v6 start migrates your configuration. If the update causes problems, you can roll back by specifying the previous image tag in your compose file instead of latest. This is why pinning specific versions (e.g., pihole/pihole:2026.11.0, the current release on 15 November 2026; the full list is on the docker-pi-hole releases page) in production is better than using latest, even though latest is more convenient. At minimum, note which version you were running before updating so you can roll back.

Troubleshooting

Log says DNS resolution is currently unavailable, or pihole -v cannot reach github.com: the container was created before you fixed systemd-resolved. Run docker compose down, then docker compose up -d (see the section above).

Container starts but DNS does not resolve:

# Check container logs for errors
docker compose logs pihole | tail -50

# Verify port 53 is actually bound
sudo ss -lntp | grep ':53 '
# Should show the Docker proxy, not systemd-resolved

Web interface loads but shows no queries:

Your devices are not using Pi-hole for DNS. Check your router's DHCP/DNS settings and renew leases on your devices.

"Permission denied" on volume mounts:

Watch out: The most common issue: Pi-hole in Docker not resolving local hostnames. You need to set your router as a conditional forwarding destination for your local domain, or local devices will not resolve each other by name.
# The v6 image runs FTL as the "pihole" user, UID/GID 1000 by default
# (change with PIHOLE_UID / PIHOLE_GID). Make sure the directory exists
# and that user can write to it:
sudo chown -R 1000:1000 ./etc-pihole

Where you’ll meet this at work

This guide is two jobs that companies buy separately. The first is running DNS as a container with its state kept outside it. In Kubernetes, Services and Pods get DNS names from the cluster DNS records, and CoreDNS is the default implementation. The bind-mounted etc-pihole folder is the small version of a PersistentVolume, which Kubernetes describes as having a lifecycle independent of any individual Pod that uses it.

The second job is DNS-layer filtering. Cisco’s Umbrella documentation lists DNS-layer security alongside its firewall and secure web gateway features, and web content filtering in Microsoft Defender for Endpoint blocks website categories on managed devices.

What maps one to one: a blocklist is a category policy, the query log is where you start when someone says a site is broken, and the container is replaced rather than repaired. What doesn’t: Pi-hole only filters devices that use it as their resolver, there is no central management across sites, and a single container is a single point of failure. The home version teaches the habit that transfers: when DNS misbehaves, check what is listening on port 53 and which resolver each layer, host and container, is really using.

Key Takeaways

  • Fix systemd-resolved before starting. The port 53 conflict is an Ubuntu default, not a Docker issue. Disable the stub listener, fix the resolv.conf symlink and restart Docker first. If the container was already created, docker compose down then up -d.
  • Bridge networking is simpler, host networking gives better visibility. Bridge mode can lose per-device query attribution (anything that goes through Docker’s userland proxy) and cannot do DHCP without a relay. Host mode avoids both. Choose based on whether you need group management and DHCP.
  • Volumes are your data. The container is disposable. The etc-pihole volume contains everything that matters. Never delete them unless you mean it.
  • Test DNS from another device before changing your router. Pointing your network at a non-functional DNS server takes down everyone's internet.
  • Use the v6 variable names. WEBPASSWORD, PIHOLE_DNS_ and friends are ignored by every image after 2024.07.0. Use the FTLCONF_ names.
  • Pin your image version in production, and update the pin. Using latest is convenient until an update breaks something and you do not know what version you were on before. A pinned tag never moves on its own, so check the releases page when you review the stack.

Related Guides

Related Guides

If you found this useful, these guides continue the journey:

The RTM Essential Stack - Gear I Actually Use

Enjoyed this guide?

New articles on Linux, homelab, cloud, and automation every 2 days. No spam, unsubscribe anytime.

Scroll to Top