Looking for a way to automate pi-hole updates with custom addlist entries, on Windows using Docker? Here’s what I did:

Pre-reqs:

  • Download Docker for Windows and install
  • Create a new batch file, e.g. “update_pihole.bat” with the content below
    • Change the docker run parameters, e.g. change the server IP/password/TimeZone/DNS2 and DNS3 (leave DNS1 to the default 127.17.0.1)
    • Create a scheduled task on the Windows host that runs the script periodically, e.g. every month. Test the task to see if it’s working.
  • Make sure the host can resolve DNS to download the latest pi-hole container after the script stops the running pi-hole docker container. I’ve configured a secondary DNS on my Windows host to point at my ISP’s DNS server directly.
  • Change your router’s DHCP to hand out IP’s with the DNS pointing to your Windows host/pi-hole’s IP.

@echo off
REM Update a pi-hole container on Windows using Docker and adding a bunch of custom addlists 
REM Latest script can be found on https://pieter.wigleven.com/it/archives/187

REM Stop and delete existing pi-hole container
docker stop pihole
docker rm pihole

REM Clear out the Docker cache and all unused images (i.e. the out of date version of pi-hole).
docker image prune -a --force

REM Pull latest pihole container, make sure your host can resolve DNS at this point!
docker pull pihole/pihole

REM Run pihole with customized parameters (change this to match your environment)
docker run -d --name pihole -e ServerIP=192.168.1.5 -e WEBPASSWORD=abcdefgh -e TZ=Europe/Amsterdam -e DNS1=127.17.0.1 -e DNS2=8.8.8.8 -e DNS3=1.1.1.1 -p 80:80 -p 53:53/tcp -p 53:53/udp -p 443:443 --restart=unless-stopped pihole/pihole:latest

REM Add custom addlist by modifying the database (ugly but only method AFAIK...)
docker exec pihole sqlite3 /etc/pihole/gravity.db "INSERT INTO adlist (address, enabled, comment) VALUES ('https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt', 1, 'comment');"
docker exec pihole sqlite3 /etc/pihole/gravity.db  "INSERT INTO adlist (address, enabled, comment) VALUES ('https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt', 1, 'comment');"
docker exec pihole sqlite3 /etc/pihole/gravity.db  "INSERT INTO adlist (address, enabled, comment) VALUES ('https://dbl.oisd.nl/', 1, 'comment');"
docker exec pihole sqlite3 /etc/pihole/gravity.db  "INSERT INTO adlist (address, enabled, comment) VALUES ('https://raw.githubusercontent.com/PolishFiltersTeam/KADhosts/master/KADhosts.txt', 1, 'comment');"

REM Update Gravity to download contents of custom addlists
docker exec pihole pihole updateGravity

Consider leaving a reply if you found this to be helpful

Post A Comment