Pihole, from 0 to home «production» with docker-compose

I will be installing Ubuntu Server 20.04 as my base distro for this. For ease of use, during the install, select Install of open ssh server.

Once installed, log in and…

  1. Update all the things.
# apt update
# apt upgrade

2. Set up automatic updates: https://linoxide.com/enable-automatic-updates-on-ubuntu-20-04/

3. Set up log2ram (Optional, recommended for Raspberry Pi’s using SDCards): https://github.com/azlux/log2ram

4. Install docker and docker-compose: https://pepdoesthings.wordpress.com/2021/08/12/starting-out-with-docker-and-docker-compose-installation-in-ubuntu-debian-based/

5. Set up pihole+unbound docker container; create from your user a docker directory and inside you will need a config directory and two files, docker-compose.yml and an .env file.

docker-compose.yml

version: '3.6'
services:
  pihole:
    container_name: pihole
    image: cbcrowe/pihole-unbound:2021.12.1
    hostname: piholevm
    domainname: piholevm.local
    environment:
      ServerIP: ${ServerIP}
      TZ: ${TZ}
      WEBPASSWORD: ${WEBPASSWORD}
      REV_SERVER: ${REV_SERVER}
      REV_SERVER_TARGET: ${REV_SERVER_TARGET}
      REV_SERVER_DOMAIN: ${REV_SERVER_DOMAIN}
      REV_SERVER_CIDR: ${REV_SERVER_CIDR}
      DNS1: 127.0.0.1#5335 # Hardcoded to our Unbound server
      DNS2: 127.0.0.1#5335 # Hardcoded to our Unbound server
      DNSSEC: "true" # Enable DNSSEC
    network_mode: host
    volumes:
      - ${DOCKERDIR}/config/pihole/etc-pihole:/etc/pihole/
      - ${DOCKERDIR}/config/pihole/etc-dnsmasq.d/:/etc/dnsmasq.d/
    restart: unless-stopped

.env

DOCKERDIR=/home/pep/docker
USERHOME=/home/pep

#PIHOLE
ServerIP=192.168.0.15 #Your own pihole server IP
TZ=Europe/Madrid
WEBPASSWORD=---the web password for your pihole---
REV_SERVER=true
REV_SERVER_DOMAIN=local
REV_SERVER_TARGET=192.168.0.1
REV_SERVER_CIDR=192.168.0.0/24

Now if you try to start your pihole it will start but it won’t fully work because Ubuntu comes with already a DNS services installed and running, so we need to dissable it first (or change its port):

$ sudo systemctl stop systemd-resolved
$ sudo systemctl disable systemd-resolved
$ sudo systemctl mask systemd-resolved

Ref: https://askubuntu.com/questions/191226/dnsmasq-failed-to-create-listening-socket-for-port-53-address-already-in-use

Once done this, you can now start your docker compose containers with (you need to be in your docker directory)

$ docker-compose up -d

6. Optional, if this is your secondary pihole, you can sync it with your first pihole: https://pepdoesthings.wordpress.com/2022/02/09/syncing-two-pihole-instances/

7. Set up automatic upgrades for your containers: https://pepdoesthings.wordpress.com/2022/02/08/update-your-docker-compose-containers-on-a-schedule/

8. Arrange crontab to update everything periodically:

0 4 * * 6 /home/pep/bin/update.containers.sh  >/dev/null 2>&1
0 5 * * 6 /home/pep/bin/piholesync.sh  >/dev/null 2>&1