Imagine a Raspberry Pi gathering dust in a drawer. Once it was a fun project, and now it does nothing. A pi-hole docker setup turns that forgotten board into the post office of your home network. Each phone, laptop and TV asks it for directions. It quietly bins the junk mail.
You are in good company. The official image on GitHub has about 11.7k stars. In plain words, one small box guards each device in the house. That is it. You install nothing on each phone.
In this tutorial, we build it with Docker Compose. It starts containers from one text file. A container is a sealed box. It holds an app and all it needs. You will free up door 53, write one file and start the box. If you are new to Docker, first install Docker on Ubuntu. The whole job takes about half an hour.
What Pi-hole Docker Does for Your Network

Think of the internet as a huge city. Each website lives at a numbered address. Yet you only know its name. DNS turns a name into an address.
Pi-hole is a DNS server that lives in your home. It works like a local post office. Each device hands it a name. It gets an address back. Sometimes the name belongs to a known junk sender. Then Pi-hole answers with a dead end, and the junk never reaches your door. For all other names, it asks a bigger post office. That is called an upstream server. So pages load as usual, and only the clutter is gone.
Why run Pi-hole in Docker? The official Docker guide packs the whole app into one ready-made image. There is nothing to build. Also, the setup lives in one file. So you can rebuild your Pi-hole Docker box in minutes.
Before You Start: Free Port 53
Here is the trap that stops most beginners. Lookups travel through port 53, a numbered door on your machine. Only one program can hold a door at a time. Two shops cannot share one street number. On most Ubuntu installs, a service called systemd-resolved already holds it. The Pi-hole community guide names this as the usual cause. Check who holds the door:
sudo lsof -i -P -n | grep LISTENLook for a line that ends in :53. If it names systemd-resolved, ask it to leave. First, copy the settings file so you can undo the change, then open it:
sudo cp /etc/systemd/resolved.conf /etc/systemd/resolved.conf.bak
sudo nano /etc/systemd/resolved.confFind the line #DNSStubListener=yes. Remove the # and change the value, so it reads:
DNSStubListener=noThe stub listener is the small helper that grabbed door 53. Save the file and restart the service:
sudo systemctl restart systemd-resolvedRun the lsof command again. This time, no line with :53 should name systemd-resolved. To undo it, copy the .bak file back and restart the service.
Set Up the Pi-hole Docker Folder and Compose File
A container forgets its data when you remove it. Think of a hotel room cleaned after checkout. So you need a filing cabinet outside the room. Here, that cabinet is a plain folder on your disk. Make it now:
mkdir -p ~/pihole/etc-pihole && cd ~/piholeThe etc-pihole folder holds the databases and settings, so they survive updates. It fits any machine, like the one from our home server guide.
Next comes the Compose file, your recipe card. Create it with nano docker-compose.yml inside the folder and paste this. It follows the official quick start, with a few settings added:
services:
pihole:
container_name: pihole
image: pihole/pihole:latest
ports:
- "53:53/tcp"
- "53:53/udp"
- "80:80/tcp"
- "443:443/tcp"
environment:
TZ: 'Europe/London'
FTLCONF_webserver_api_password: 'choose-a-strong-password'
FTLCONF_dns_upstreams: '1.1.1.1;1.0.0.1'
FTLCONF_dns_listeningMode: 'ALL'
volumes:
- './etc-pihole:/etc/pihole'
restart: unless-stopped- Ports: 53 is the lookup door, 80 is the web page, and 443 is HTTPS.
- Time zone: logs rotate at your local midnight.
- Upstreams: the servers Pi-hole asks for names it does not block.
- Restart: the container comes back after a reboot, unless you stopped it.
Change the password and time zone to your own. Keep the quotes and spacing exactly as shown. Environment variables are the recommended way to configure the box.
Start Pi-hole Docker and Open the Web Page
Time to switch it on. From inside your project folder, run this:
docker compose up -d
docker psThe -d flag runs the container in the background. The second command should show a row for your container. Its status should start with Up. If the row is missing, run docker logs pihole to read the error.
Next, open http://<your-machine-ip>/admin in a browser. Sign in with the password from your file. Think of that password as the key to the post office back room. No password set? Then Pi-hole picks a random one and prints it in the log:
docker logs pihole | grep "random password"Be careful with one detail from the configuration guide. An empty password variable means no password at all. So always set a strong one.
Your Pi-hole Docker box is now alive, but no device uses it yet. Before the next step, give the machine a static IP address in your router. Otherwise the address can change. Then each device will knock on an empty building.
Point Your Devices at Pi-hole and Add Blocklists

Start with one device, like your laptop. Open its network settings and set its DNS server to the Pi-hole machine’s IP address. Then visit a few sites. The query count on the dashboard should climb, which proves the post office is open. Check from your laptop, too:
nslookup example.com <your-machine-ip>Once one device works, open your router’s settings page. Find the DNS field, often under LAN settings. Enter the machine’s address there. Warning: a wrong change here takes the whole house offline. So write down the old value first. Away from home? You can reach Pi-hole via Tailscale instead of opening a door to the internet.
Now add blocklists. Open the lists page, paste the address of a list, and save. Then run the update gravity action from the Tools menu. A bigger list is not always better. Start with one or two from sources you trust. If a page breaks, allow that one name. Finally, read the stats to see what your devices ask for.
Keep Your Pi-hole Docker Setup Healthy

Each post office has a bad day. If the web page will not load, run docker ps and read the log. If the internet stops after the change, put the old router setting back first. Then check that the container runs. If DHCP fails, remember that broadcasts cannot cross Docker’s bridge network, as the DHCP guide explains. Use host networking or leave DHCP on your router.
Next, pin the image. The latest tag always pulls the newest release, while a date tag pins one exact build:
image: pihole/pihole:<release-tag>Then back up your settings with one command, and run it before every upgrade:
tar -czf ~/pihole-backup.tar.gz -C ~/pihole etc-piholeAlso, keep the container’s powers small. The project page says NET_ADMIN is only needed for DHCP. Never use –privileged.
Let’s go back to the drawer. That idle board now runs the post office of your home. If you enjoy running your own services, try your own cloud on the same machine next. Your network is quieter now, and it is truly yours.
Frequently Asked Questions
No. Pi-hole is a lookup service that blocks known junk names. It does not encrypt your traffic or hide your IP address, so it does not replace a VPN.
Often not. Pi-hole blocks by name, and video ads can come from the same names as the video itself. It cannot block one without the other.
No. Any Linux machine that runs Docker will do, such as an old laptop or a small home server. The Raspberry Pi is just a cheap and quiet choice.
Devices that rely only on it cannot look up names, so pages stop loading until it is back. The restart setting in your file brings the container back after a reboot. If the whole house goes offline, put the old setting back.










































