How To Install PiHole Using Docker on Raspberry Pi

Pi-hole or Pihole is a Linux network-level advertisement and Internet tracker blocking application which acts as a DNS sinkhole and optionally a DHCP server, intended for use on a private network.


This tutorial will require you to prepare a Raspberry Pi with Docker engine installed. You can follow this tutorial to install Docker on Raspberry Pi. We would recommend you to use Raspberry Pi 4 to get a better performance. You can get it from Cytron Marketplace.

Step 1 : Stop systemd-resolved from using port 53 on Raspberry Pi

By default Raspberry Pi OS is listening on port 53. But unfortunately, port 53 is required for PiHole usage. So we need to configure Raspberry Pi OS to disable the use of port 53.

To do that, uncomment line “DNSStubListener” and change it to “no”

sudo nano /etc/systemd/resolved.conf

Restart systemd-resolved to apply the setting

systemctl restart systemd-resolved

Verify port 53 has been free using net-tools

netstat -tunlp | grep 53

If you are not able to use the command, please install net tools by execute apt install net-tools

tcp        0      0  *               LISTEN      10583/systemd-resol
tcp6       0      0 :::5355                 :::*                    LISTEN      10583/systemd-resol
udp        0      0  *                           363/avahi-daemon: r
udp        0      0  *                           10583/systemd-resol
udp6       0      0 :::5353                 :::*                                363/avahi-daemon: r
udp6       0      0 :::5355                 :::*                                10583/systemd-resol

Step 2 : Create Docker Compose file

Create a file name docker-compose.yml and write below details :

sudo nano docker-compose.yml
version: "3.8"
    container_name: pihole
    hostname: pihole.lan
    image: pihole/pihole:latest
    restart: always
      - "53:53/tcp"
      - "53:53/udp"
      - "67:67/udp" #This is required if you enable DHCP server on PiHole
      - "8080:80/tcp"

      - './etc-pihole/:/etc/pihole/'
      - './etc-dnsmasq.d/:/etc/dnsmasq.d/'

      - TZ= 'Asia/Hong_Kong'
      - WEBPASSWORD= 'password'
      - DNS1=
      - DNS2=

     #Recommended but not required (DHCP needs NET_ADMIN)
      - NET_ADMIN

Step 3 : Run the docker compose file

To spin up the PiHole container, execute this command.

docker-compose up -d

Step 4 : Verify the installation

To verify the installation, access Pi-Hole using this URL : http://server_ip_address:8080/admin


Hola ! I am Cloud System Engineer and I am very passionate about Linux, Cloud & Automation !

Articles: 4