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.

Pre-reqs:
  • 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 127.17.0.1). 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.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@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=192.168.1.5 -e WEBPASSWORD=abcdefgh -e TZ=Europe/Amsterdam[/b] -e DNS1=127.17.0.1 -e [b]DNS2=8.8.8.8 -e DNS3=1.1.1.1[/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 ('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


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

Comments


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 https://www.pivpn.io/ 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 https://www.pivpn.io/ 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 www.links-for.site

Comments are closed