Pi‑hole is a free, open‑source network‑wide ad blocker that works as a DNS sinkhole, intercepting DNS requests and blocking ads, trackers, and malicious domains before they reach your devices. It runs on lightweight Linux systems (often a Raspberry Pi) but can be installed on almost any server or container
sudo apt update && sudo apt upgrade -ycurl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh
sudo apt install docker-compose-pluginsudo usermod -aG docker $USERsudo systemctl enable dockersudo rebootdocker run hello-worldmkdir ~/docker/pihole
In ~/docker/pihole create docker-compose.yml
networks:
macvlan_net:
driver: macvlan
driver_opts:
parent: eth0 # Use ifconfig to find this. It's probably eth0.
ipam:
config:
- subnet: 192.168.86.0/24 # You can find this by running ip addr show eth0 on your Pi
gateway: 192.168.86.1 # You can find this by running ip route | grep default on your Pi
services:
pihole:
image: pihole/pihole
container_name: pihole
networks:
macvlan_net:
ipv4_address: 192.168.86.xx #Assign a static IP within your subnet
security_opt:
- no-new-privileges:false
restart: on-failure:5 # This makes sure that pihole is pretty much always up
volumes:
- <your-docker-directory>/pihole/pihole:/etc/pihole:rw
- <your-docker-directory>/pihole/dnsmasq.d:/etc/dnsmasq.d:rw
environment:
FTLCONF_webserver_api_password: <assign a pssword you want to use to log in>
FTLCONF_webserver_port: 8080 # port 8080 is a pretty common port so you can set this to any unused port that you want
FTLCONF_dns_listeningMode: all
TZ: America/New_York
DNSMASQ_USER: pihole #or root (don't use root)
PIHOLE_UID: 1000
PIHOLE_GID: 10
cap_add:
- SYS_TIME
- SYS_NICE
From within ~/docker/pihole run:
docker compose up -d
View logs for pihole
docker logs pihole
Go to your router and set your primary DNS server to the address you set in your compose file.
Open your browser and go to http://<the address you defined in the compose file>:<FTLCONF_webserver_port as defined in the compose file>
Example: 192.168.86.xx:8080
If you find my content useful, please consider supporting this page: