pi-hole / docker-pi-hole

Pi-hole in a docker container
https://pi-hole.net
Other
8.58k stars 1.13k forks source link

Include my own pi-hole config. #329

Closed mogaal closed 6 years ago

mogaal commented 6 years ago

With environment variables we have some kind of limitation where it isn't possible to set up things like dhcp. Trying to find other ways to include custom set up/config at the container runtime I ended up changing start.sh script to include my own config commands. The Dockerfile is as simplest as:

FROM pihole/pihole:latest

COPY start.sh /

Where it is added to the same start.sh we got in the repo the following three lines:

....
setup_lighttpd_bind "$ServerIP"
setup_blocklists

# Custom set-up
if [ -f /my-config.sh ]; then
    bash my-config.sh
fi

test_configs
....

And inside my-config.sh:

/usr/local/bin/pihole -a enabledhcp '192.168.1.10' '192.168.1.100' '192.168.1.1' '24' 'home.local' false
/usr/local/bin/pihole -a addstaticdhcp 'F0:18:88:11:D2:1B' '192.168.1.50' 'Work-Laptop'
/usr/local/bin/pihole -a addstaticdhcp '00:21:3A:EA:5F:1B' '192.168.1.40' 'COSI-DESKTOP-WIFI'
....
etc

Is it something I should consider a PR? Any better Idea? I also though about including a lot of DHCP env variables but it was easier and quicker this way. Any comments/ideas suggestions?

Alejandro

diginc commented 6 years ago

There are a couple ways to approach this, my top choice would just be save the DNSMasq settings you need out of the container using a docker volume. Make sure you start your container using the recommended volumes from the readme, I believe dnsmasq is one of those folders and could contain all the settings you appear to be modifying. Then instead of using a script run your commands through docker exec pihole where pihole is the name of your pi-hole container from docker ps (it's random if you didn't assign a hard coded name). So your commands would become this:docker exec dockerpihole pihole -a enabledhcp '192.168.1.10' '192.168.1.100' '192.168.1.1' '24' 'home.local' false and then be saved to a docker volume for future re-use whenever the container is re-created.

Another way, which may be more in line with your existing script but wouldn't require building/baking it into the image would be just volume mount the script in to the default image. The first way to try would be mount it into /etc/cont-init.d/ folder, which will land right beside the 20-start.sh script, make it have a lower number to run before that and a higher number to run after. I'd say go for something like 30-custom.sh with your existing script and see if it works.