Go to file
Adam Hill 28b57e9c01 Merge pull request #106 from diginc/README
Web Password and updated documentation
2017-02-09 11:10:10 -06:00
alpine remove php.ini full copy for extension addition 2017-02-01 12:49:46 -06:00
test Add web password support 2017-02-08 22:46:46 -06:00
.gitignore Fix to debian lighttpd php config #19 w/tests 2016-07-16 16:00:20 -05:00
.gitmodules remove submodules 2017-01-17 23:16:11 -06:00
.travis.yml pytest error go away 2017-01-17 22:48:25 -06:00
Dockerfile alpine nginx pihole working, weighing in at 85.36 MB vs debian 252.4 MB 2016-02-13 13:24:44 -06:00
README.md Update README.md 2017-02-09 10:52:41 -06:00
alpine.docker remove php.ini full copy for extension addition 2017-02-01 12:49:46 -06:00
autotest fixing shellcheck errors from master 2016-10-22 13:39:12 -05:00
bash_functions.sh Add web password support 2017-02-08 22:46:46 -06:00
debian-armhf.docker re-do a few things to fix up test/handle updated code 2017-01-17 22:49:42 -06:00
debian.docker re-do a few things to fix up test/handle updated code 2017-01-17 22:49:42 -06:00
docker-compose.yml alpine nginx pihole working, weighing in at 85.36 MB vs debian 252.4 MB 2016-02-13 13:24:44 -06:00
docker-pi-hole.cron debian images building, alpine WIP 2017-01-08 10:42:39 -06:00
docker_dev.sh Update docker_dev.sh 2017-01-09 12:05:40 -06:00
docker_run.sh Documentation and run cmd updates 2017-02-03 00:05:34 -06:00
doco-alpine.yml Documentation and run cmd updates 2017-02-03 00:05:34 -06:00
doco-debian.yml Documentation and run cmd updates 2017-02-03 00:05:34 -06:00
doco-example.yml Documentation and run cmd updates 2017-02-03 00:05:34 -06:00
install.sh switch how we pin to fix our web interface version 2017-02-01 16:37:53 -06:00
jwilder-proxy-example-doco.yml updating the docker compose examples 2016-09-23 21:24:14 -05:00
make_symlinks.sh Shellcheck added to py.test and fixes 2016-10-08 14:56:06 -05:00
requirements.txt re-do a few things to fix up test/handle updated code 2017-01-17 22:49:42 -06:00
start.sh Add web password support 2017-02-08 22:46:46 -06:00

README.md

A Docker project to make lightweight x86 and ARM container with pi-hole functionality. Why? Maybe you don't have a Raspberry Pi lying around but you do have a Docker server.

Now with ARM (actual docker-pi) support! Just install docker on your Rasberry-Pi and run docker image diginc/pi-hole:arm tag (see below for full required command).

  • The current Raspbian install is simply curl -sSL https://get.docker.com | sh [1]

Build Status Docker Stars Docker Pulls

Join the chat at https://gitter.im/diginc/docker-pi-hole

Running Pi-Hole Docker

DockerCloud automatically builds the latest docker-pi-hole changes into images which can easily be pulled and ran with a simple docker run command.

One crucial thing to know before starting is the docker-pi-hole container needs port 53 and port 80, 2 very popular ports that may conflict with existing applications. If you have no other services or dockers using port 53/80 (if you do, keep reading below for a reverse proxy example), the minimum options required to run this container are in the script docker_run.sh or summarized here:

IMAGE='diginc/pi-hole'
IP_LOOKUP="$(ip route get 8.8.8.8 | awk '{ print $NF; exit }')"  # May not work for VPN / tun0
IP="${IP:-$IP_LOOKUP}"  # use $IP, if set, otherwise IP_LOOKUP
docker run -p 53:53/tcp -p 53:53/udp -p 80:80 --cap-add=NET_ADMIN -e ServerIP="$IP" --restart=always --name pihole -d $IMAGE

# Recommended auto ad list updates & log rotation:
wget -O- https://raw.githubusercontent.com/diginc/docker-pi-hole/master/docker-pi-hole.cron | sudo tee /etc/cron.d/docker-pi-hole

This is just an example and might need changing. As mentioned on line 2, the auto IP_LOOKUP variable may not work for VPN tunnel interfaces.

Automatic Ad List Updates - docker-pi-hole.cron is a modified version of upstream pi-hole's crontab entries using docker exec to run the same update scripts inside the docker container. The cron automatically updates pi-hole ad lists and cleans up pi-hole logs nightly. If you're not using the docker run with --name pihole from default container run command be sure to fill in your container's DOCKER_NAME into the variable in the cron file.

Environment Variables

In addition to the required environment variable you saw above (-e ServerIP="$IP") there are optional ones if you want to customize various things inside the docker container:

Env Variable Default Description
ServerIP REQUIRED! Set to your server's external IP in order to override what Pi-Hole users. Pi-Hole auto discovers the unusable internal docker IP otherwise
WEBPASSWORD Set this to your desired password or on first boot we'll randomly set one. docker logs pihole can tell you what it got set to. To change it check out the tips below
DNS1 8.8.8.8 Primary upstream DNS for Pi-Hole's DNSMasq to use, defaults to google
DNS2 8.8.4.4 Secondary upstream DNS for Pi-Hole's DNSMasq to use, defaults to google
VIRTUAL_HOST Server_IP What your web server 'virtual host' is, accessing admin through this Hostname/IP allows you to make changes to the whitelist / blacklists in addition to the default 'http://pi.hole/admin/' address
IPv6 True Allows forced disabling of IPv6 for docker setups that can't support it (like unraid)

Tips and Tricks

  • A good way to test things are working right is by loading this page: http://pi.hole/admin/
  • How do I set or reset the Web interface Password?
  • docker exec pihole_container_name pihole -a -p supersecurepassword
  • Port conflicts? Stop your server's existing DNS / Web services.
  • Ubuntu users especially may need to shutoff dnsmasq on your docker server so it can run in the container on port 53
  • Don't forget to stop your services from auto-starting again after you reboot
  • Port 80 is highly recommended because if you have another site/service using port 80 by default then the ads may not transform into blank ads correctly. To make sure docker-pi-hole plays nicely with an existing webserver you run you'll probably need a reverse proxy webserver config if you don't have one already. Pi-Hole has to be the default web app on said proxy e.g. if you goto your host by IP instead of domain then pi-hole is served out instead of any other sites hosted by the proxy. This is the 'default_server' in nginx or 'default' virtual host in Apache and is taken advantage of so any undefined ad domain can be directed to your webserver and get a 'blocked' response instead of ads.
  • You can still map other ports to pi-hole port 80 using docker's port forwarding like this -p 8080:80, but again the ads won't render propertly. Changing the inner port 80 shouldn't be required unless you run docker host networking mode.
  • Here is an example of running with jwilder/proxy (an nginx auto-configuring docker reverse proxy for docker) on my port 80 with pihole on another port. Pi-hole needs to be DEFAULT_HOST env in jwilder/proxy and you need to set the matching VIRTUAL_HOST for the pihole's container. Please read jwilder/proxy readme for more info if you have trouble. I tested this basic example which is based off what I run.

Volume Mounts

Here are some useful volume mount options to persist your history of stats in the admin interface, or add custom whitelists/blacklists. Create these files on the docker host first or you'll get errors:

  • docker run -v /var/log/pihole.log:/var/log/pihole.log ... (plus all of the minimum options added)
  • touch /var/log/pihole.log on your docker server first or you will end up with a directory there (silly docker!)
  • docker run -v /etc/pihole/:/etc/pihole/ ... (plus all of the minimum options added)

All of these options get really long when strung together in one command, which is why I'm not showing all the full docker run commands variations here. This is where docker-compose yml files come in handy for representing really long docker commands in a readable file format.

Docker tags and versioning

The primary docker tags / versions are explained in the following table. Click here to see the full list of tags, I also try to tag with the specific version of Pi-Hole Core for version pinning purposes, the web version that comes with the core releases should be in the GitHub Release notes.

tag architecture description Dockerfile
alpine / latest x86 Alpine x86 image, small size container running nginx and dnsmasq Dockerfile
debian x86 Debian x86 image, container running lighttpd and dnsmasq Dockerfile
arm ARM Debian ARM image, container running lighttpd and dnsmasq built for ARM Dockerfile

diginc/pi-hole:alpine

Alpine is also the default, aka latest tag. If you don't specify a tag you will get this version. This is only an x86 version and will not work on Raspberry Pi's ARM architecture. Use this if you like a small image.

diginc/pi-hole:debian

This version of the docker aims to be as close to a standard pi-hole installation by using the same base OS and the exact configs and scripts (minimally modified to get them working). This serves as a stable baseline for merging and testing upstream repository pi-hole changes. Use this if you don't care about image size and want as stable of a product as possible.

diginc/pi-hole:arm

Same as the debian image, but cross compiled for ARM architecture hardware through resin.io's awesome Qemu wrapper.

Alpine doesn't have an arm cross compilable image at this time.

Upgrading, Persistence, and Customizations

The standard pi-hole customization abilities apply to this docker, but with docker twists such as using docker volume mounts to map host stored file configurations over the container defaults. Volumes are also important to persist the configuration in case you have removed the pi-hole container which is a typical docker upgrade pattern.

Upgrading

If you try to use pihole's built in updater it is not guaranteed to work; it almost assuredly won't work for alpine but debian may. The preferred 'docker way' to upgrade is:

  1. Download the latest version of the image: docker pull diginc/pi-hole
  2. Throw away your container: docker rm -f pihole
  • Warning When removing your pihole container you may be stuck without DNS until step 3 - docker pull before you docker rm -f to avoid DNS inturruption OR always have a fallback DNS server configured in DHCP to avoid this problem all together.
  • If you care about your data (logs/customizations), make sure you have it volume mapped or it will be deleted in this step
  1. Start your container with the newer base image: docker run <args> diginc/pi-hole (<args> being your preferred run volumes and env vars)

Why is this style of upgrading good? A couple reasons: Everyone is starting from the same base image which has been tested to know it works. No worrying about upgrading from A to B, B to C, or A to C is required when rolling out updates, it reducing complexity, and simply allows a 'fresh start' every time while preserving customizations with volumes. Basically I'm encouraging phoenix servers principles for your containers.

Persisting pihole volume

-v my-pihole-configs/:/etc/pihole/ Volume mapping the entire /etc/pihole directory is the easiest way to save all your customizations. Clear out the directory if you want to start from scratch.

Pihole features

Here are some relevant wiki pages from pi-hole's documentation. The web interface or command line tools can be used to implement changes to pihole.

We install all pihole utilities so the the built in pihole commands will work via docker exec <container> <command> like so:

  • docker exec pihole_container_name pihole updateGravity
  • `docker exec pihole_container_name pihole -w spclient.wg.spotify.com
  • `docker exec pihole_container_name pihole -wild example.com

Customizations

The webserver and DNS service inside the container can be customized if necessary. Any configuration files you volume mount into /etc/dnsmasq.d/ will be loaded by dnsmasq when the container starts or restarts or if you need to modify the pi-hole config it is located at /etc/dnsmasq.d/01-pihole.conf. The docker start scripts runs a config test prior to starting so it will tell you about any errors in the docker log.

Similarly for the webserver you can customize configs in /etc/nginx (:alpine tag) and /etc/lighttpd (:debian tag).

Development Build Status

If you plan on making a contribution please pull request to the dev branch. I also build tags of the dev branch for bug fix testing after merges have been made:

tag architecture description Dockerfile
alpine_dev x86 Alpine x86 image, small size container running nginx and dnsmasq Dockerfile
debian_dev x86 Debian x86 image, container running lighttpd and dnsmasq Dockerfile
arm_dev ARM Debian ARM image, container running lighttpd and dnsmasq built for ARM Dockerfile

User Feedback

Please report issues on the GitHub project when you suspect something docker related. Pi-Hole questions are best answered on their user forums. Ping me (@diginc) on there if it's a docker and you're not sure if it's docker related.