Pi-hole with Docker - Installation and Setup

In my previous post, I've covered Pi-hole installation and setup with LXD. For this post, we will try another installation approach, using Docker. Procedure wise, it's quite straightforward, just three steps.
$ docker pull pihole/pihole
$ wget https://raw.githubusercontent.com/pi-hole/docker-pi-hole/master/docker_run.sh
$ bash docker_run.sh

One of the issue that encountered was that the mapped ports maybe have been used for other services. to resolve the port conflicts, especially those using Ubuntu, we have to identify those processes that bind to those ports and stop it.
$ sudo netstat -nltup | grep -E ":53|:67|:80|:443"

Port conflicts with Dnsmasq in Ubuntu can be resolved by disabling its service. However, this is not advisable if you're running services that depends on Dnsmasq like LXD or VPN.

If you like alternative way to properly manage (for example, restarting) the Pi-hole's container, you can write a wrapper shell script and manage it through Docker Compose.

The wrapper shell script based on the `docker-run.sh`.
#!/usr/bin/env bash

IP_LOOKUP="$(ip route get | awk '{for(i=1;i<=NF;i++) if ($i=="src") print $(i+1)}')"
IPV6_LOOKUP="$(ip -6 route get 2001:4860:4860::8888 | awk '{for(i=1;i<=NF;i++) if ($i=="src") print $(i+1)}')"


TIMEZONE="$(cat /etc/timezone)"


exec docker-compose [email protected]

And our `docker-compose.yml` file, modified based on this sample.
version: '2'
    container_name: pihole
    restart: unless-stopped
    image: pihole/pihole
    - ServerIP=$IP
    - ServerIPv6=$IPv6
    - WEBPASSWORD=*foobar*
    - DNS1=
    - DNS2=
    - $DOCKER_CONFIGS:/etc/pihole/
    - $DOCKER_CONFIGS/dnsmasq.d/:/etc/dnsmasq.d/
    - "80:80"
    - "443:443"
    - "53:53/tcp"
    - "53:53/udp"
    - "67:67/udp"

No comments:

Post a Comment