Build your own ad blocker with Docker and Pi-hole

Pi-hole is a network-level ad blocker that works as a DNS sinkhole. Instead of installing browser extensions on every device, Pi-hole blocks unwanted domains for the entire network.

Prepare Docker

sudo systemctl start docker

If another local resolver is using port 53, stop and disable it before running Pi-hole:

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

Docker Compose example

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: 'America/Argentina/Buenos_Aires'
    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

Network configuration

Point your router or devices to the Pi-hole server as DNS. Start with default blocklists and add custom rules gradually to avoid blocking required services.

Maintenance

Keep Docker images updated, review blocked domains when something stops working and back up Pi-hole settings before major changes.

Leave a Reply