Pi-Hole in Docker

1 minute read

disable systemd-resolved stub

First, disable systemd-resolved name server stub. You can use this command to do this:

# This just changes "#DNSStubListener=yes" to "DNSStubListener=no"
sudo sed -r -i.orig 's/#?DNSStubListener=yes/DNSStubListener=no/g' /etc/systemd/resolved.conf

You also have to remove the symlink /etc/resolv.conf, and replace it with a file:

rm /etc/resolv.conf
echo "nameserver 1.1.1.1" >  /etc/resolv.conf
echo "nameserver 8.8.8.8" >> /etc/resolv.conf

Then do systemctl restart systemd-resolved. (Source)

run pi-hole in docker-compose

I am using this docker-compose.yml file for pi-hole:

version: "3"

# More info at https://github.com/pi-hole/docker-pi-hole/ and https://docs.pi-hole.net/
services:
  pihole:
    container_name: pihole
    image: pihole/pihole:latest

    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "67:67/udp"
      - "80:80/tcp"

    environment:
      ServerIP: "192.168.1.2"     # ADJUST FOR YOUR PI-HOLE IP OF COURSE
      TZ: 'Europe/Berlin'
      WEBPASSWORD: 'mysupersecretpassword'

    volumes:
      - './data/etc-pihole/:/etc/pihole/'
      - './data/etc-dnsmasq.d/:/etc/dnsmasq.d/'

    dns:                          # THIS IS IMPORTANT
      - 127.0.0.1                 # SPECIALLY THIS LINE. I DON'T KNOW WHY.
      - 172.198.179.1

    # Recommended but not required (DHCP needs NET_ADMIN)
    #   https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
    cap_add:
      - NET_ADMIN

    restart: unless-stopped

Update pi-hole entries

Then update the pi-hole when it runs under: WebUI -> Tools -> Update Gravity -> Press “Update”.