PiHole on Raspberry Pi

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

🔍 What PiHole Does

🚀 Docker Installation Steps

  1. Update your system
    sudo apt update && sudo apt upgrade -y
  2. Install Docker
    curl -fsSL https://get.docker.com -o get-docker.sh
    sudo sh get-docker.sh
  3. Install Docker Compose
    sudo apt install docker-compose-plugin
  4. Add your user to the Docker group
    sudo usermod -aG docker $USER
  5. Enable Docker at boot
    sudo systemctl enable docker
  6. Reboot
    sudo reboot
  7. Test Docker
    docker run hello-world

📁 Setup PiHole

mkdir ~/docker/pihole

🧾 Docker Compose File

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

▶️ Start PiHole

From within ~/docker/pihole run:

docker compose up -d

📜 View Logs

View logs for pihole

docker logs pihole

Configure your router

Go to your router and set your primary DNS server to the address you set in your compose file.

🌐 Access Web Interface

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:

☕ Buy Me a Coffee