Automating Pi-hole updates with addlist customization on Windows with Docker

By Pwigle on woensdag 22 december 2021 15:54 - Comments (8)
Category: -, Views: 5.006

For those that never heard of Pi-hole, it's worth looking into! Instead of browser plugins or other software on each computer, install Pi-hole in one place and your entire network is protected from adds. It's like an SSD for the internet.

In my environment I have a Intel NUC running Windows 10 for web camera recording purposes and decided it could easily run this Pi-hole task next to it.However - I don't want to be in the business of running manual updates and looked into a way to completely automate the update process of Pi-hole including customization of add block-lists - here's what I did.

  • Download Docker for Windows and install
  • Create a new batch file, e.g. “update_pihole.bat” with the content shown below
  • Change the docker run parameters, e.g. change the server IP/password/TimeZone/DNS2 and DNS3 (leave DNS1 to the default Check out line 14 in the script below.
  • 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 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 [b]ServerIP= -e WEBPASSWORD=abcdefgh -e TZ=Europe/Amsterdam[/b] -e DNS1= -e [b]DNS2= -e DNS3=[/b] -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 ('', 1, 'comment');"
docker exec pihole sqlite3 /etc/pihole/gravity.db  "INSERT INTO adlist (address, enabled, comment) VALUES ('', 1, 'comment');"

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

Every time you run the batch file, the latest version of Pi-hole will be downloaded and customized with add lists.

This is my first post on tweakblogs, consider leaving a reply if you found this to be helpful


By Tweakers user himlims_, woensdag 22 december 2021 16:06

pihole, docker ... en toen kwam er windows bij kijken (i'm out) :+

wel mooie tool, ook die vond ik praktisch

By Tweakers user Pwigle, woensdag 22 december 2021 16:10

himlims_ wrote on Wednesday 22 December 2021 @ 16:06:
pihole, docker ... en toen kwam er windows bij kijken (i'm out) :+

wel mooie tool, ook die vond ik praktisch
Had 'm eerst native (linux) op een Raspberry Pi draaien maar vond het vrij traag. Bijvoorbeeld het whitelisten van een hostname duurde meerdere seconde. Aangezien er nog een Windows instance 24/7 draaide op krachtigere hardware het naar Docker voor Windows verplaatst.

Thanks voor de pivpn tip - zal er naar kijken.

[Comment edited on woensdag 22 december 2021 16:10]

By Tweakers user Pwigle, woensdag 22 december 2021 20:38

Kende ik niet, bedankt voor delen. Updaten van de container zijn 4 commando's (wat er drie zouden kunnen zijn) het customizen van Pi-hole door entries in de DB te plaatsen is de rest.

By Tweakers user Pwigle, donderdag 23 december 2021 13:41

Thanks, zal de twee amazonaws entries verwijderen.

By lenny, vrijdag 24 december 2021 19:20

Mooi script om het automatisch op te zetten :) . Waarom gebruik je geen `docker-compose` en `docker volumes`?

By Frankseolinks, donderdag 24 februari 2022 01:18

We will help you promote your site, backlinks for the site are here inexpensive

Comments are closed