Pi-hole is a free, open-source network-wide ad blocker that blocks unwanted advertisements and internet trackers. Docker can be used to run Pi-hole in a container for easy setup and management.
- Ad Blocking: Blocks unwanted advertisements and internet trackers across the network.
- Web Interface: Provides a graphical interface to manage blocklists and monitor DNS queries.
- Network Use: Suitable for home and small office networks.
- Docker: Runs Pi-hole in a container without requiring a direct installation on the host.
Setting Up pi-hole and Docker
Step 1 Open your terminal and Start docker
sudo systemctl start dockerEnter the command to download pinhole from docker hub
sudo docker pull pihole/pihole:latestStep 2 Skip this if you are not using Ubuntu
sudo systemctl stop systemd-resolved.servicesudo systemctl disable systemd-resolved.service Step 3 Change the DNS to something else like google
sudo nano /etc/resolve.confset DNS 8.8.8.8 and save.
Step 4 Copy this code
version: "3"
services:
pihole:
container_name: pihole
image: pihole/pihole:latest
ports:
- "53:53/tcp"
- "53:53/udp"
- "67:67/udp"
- "80:80/tcp"
- "443:443/tcp"
environment:
TZ: 'Asia/Kolkata' #this is the time zone
volumes:
- './etc-pihole/:/etc/pihole/'
- './etc-dnsmasq.d/:/etc/dnsmasq.d/'
dns:
- 127.0.0.1
- 1.1.1.1
cap_add:
- NET_ADMIN
restart: unless-stopped
| Configuration | Description |
|---|---|
services / pihole | Defines the Pi-hole container. |
image | Uses the Pi-hole Docker image. |
ports | Exposes DNS, DHCP, and web interface ports to the host. |
environment | Sets configuration such as the time zone. |
volumes | Persists Pi-hole configuration and DNS settings on the host. |
dns | Specifies DNS servers for the container. |
cap_add: NET_ADMIN | Provides the network administration capability required by Pi-hole. |
restart: unless-stopped | Automatically restarts the container unless it is manually stopped. |
Now create a file named docker-compose.yml by using following command.
sudo nano docker-compose.ymlCopy the above code and paste it in the docker-compose.yml
Step 5 Run the compose file to launch pihole
sudo docker-compose up -dStep 6 Move inside pihole container
sudo docker exec -it pihole bashChange pihole password using this command.
pihole -a -pexitStep 7 Go to browser and search
http://localhost/admin/ 
Step 8 Login with the password

Now use the pihole as your DNS instead of any other.
Configure Pi-hole as the DNS Server on Windows
- Open Settings → Network & Internet.
- Select Ethernet or Wi-Fi, depending on your connection.
- Click Change adapter options.
- Right-click your active Wi-Fi/Ethernet connection and select Properties.
- Select Internet Protocol Version 4 (TCP/IPv4) → Properties.
- Select Use the following DNS server addresses.
- Enter the Pi-hole IP address as the preferred DNS server.
- Click OK to save the changes.
You can also configure the same Pi-hole IP address as the DNS server in your home router so that all connected devices use Pi-hole automatically.