Skip to content

PiHole in Docker

  • by
Pi-Hole uppsetning

So, you don’t have a Raspberry Pi and since they are about as scarce as can be these days you can’t buy one, but you want to run PiHole without having to dedicate a piece of metal for it. What can you do?

Well, if you have a home server running Linux it’s no problem! Simply run it in a Docker container! I’ll show you how.

First of all, I’m writing this as if you have an Ubuntu Server machine, so you can follow along if you have a Debian-based distro, for those who have an RPM-based system, you can still use this guide, just know that the commands are different in your case.

First of all, let’s remove anything we might have installed from the default repos:

apt-get remove docker docker-engine containerd runc

Get our system ready for Docker:

apt-get install ca-certificates curl gnupg lsb-release

Let’s add Dockers GPG keys and their repo:

mkdir -p /etc/apt/keyrings
curl -fsSL | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null

Now let’s install Docker:

apt-get update
apt-get install docker-ce docker-ce-cli docker-compose-plugin docker-compose

Now, since we’re using Ubuntu Server and it is using systemd, we have to free port 53 (which is used for DNS traffic) from systems. To do that we have to edit one file and modify it a bit.

nano -w /etc/systemd/resolved.conf

In that file, uncomment and change the following line so it looks like it does here:

DNSStubListener = no

Now we have to make one simple symlink and then reboot the server so that the settings in systemd take effect.

ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

After the reboot, we need to create a docker-compose.yml file where we want the PiHole Docker container to be created.

version: "3"
    container_name: pihole
    image: pihole/pihole:latest
      - "53:53/tcp"
      - "53:53/udp"
      - "80:80/tcp"
        TZ: 'Reykjavik/Atlantic'
      - './etc-pihole:/etc/pihole'
      - './etc-dnsmasq.d:/etc/dnsmasq.d'
    restart: unless-stopped

Now just run this command and we’re set!

docker-composer up -d

That’s it! Now you have a PiHole running on your local network! Congrats!

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.