Create your own secure Home Network using Pi-hole and Docker

Last Updated : 29 Sep, 2026

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 docker

Enter the command to download pinhole from docker hub 

sudo docker pull pihole/pihole:latest

Step 2 Skip this if you are not using Ubuntu 

sudo systemctl stop systemd-resolved.service
sudo systemctl disable systemd-resolved.service 

Step 3 Change the DNS to something else like google 

sudo nano /etc/resolve.conf

set 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
ConfigurationDescription
services / piholeDefines the Pi-hole container.
imageUses the Pi-hole Docker image.
portsExposes DNS, DHCP, and web interface ports to the host.
environmentSets configuration such as the time zone.
volumesPersists Pi-hole configuration and DNS settings on the host.
dnsSpecifies DNS servers for the container.
cap_add: NET_ADMINProvides the network administration capability required by Pi-hole.
restart: unless-stoppedAutomatically restarts the container unless it is manually stopped.

Now create a file named docker-compose.yml by using following command.

sudo nano docker-compose.yml

Copy the above code and paste it in the docker-compose.yml

Step 5 Run the compose file to launch pihole

sudo docker-compose up -d

Step 6 Move inside pihole container 

sudo docker exec -it pihole bash

Change pihole password using this command.

pihole -a -p
exit

Step 7 Go to browser and search 

http://localhost/admin/ 
Ip in browser pihole

Step 8 Login with the password 

Login Pihole

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.

Comment

Explore