Just to put it all in one place, here’s a quick walkthrough of setting up pi-hole to run on your raspberry pi using docker-compose.
- Setup
- Create a docker-compose file
- Start pi-hole
- Configure your network or clients
- Update pi-hole
Setup
I’ll link some resources here, but I’m expecting you to get this piece settled on your own. These are all very searchable things. The goal after setup is a working pi that you can get files onto, easily.
- If you’re a first timer and want to just get the OS installed, see here.
- Make sure you setup SSH as well.
- Install docker on it.
- Get a repository setup from a reputable host: github, bitbucket, gitlab (learn how to use it if need be)
Create a docker-compose file
In your repository, create 2 files:
- docker-compose.yml
- readme.md
In the first file, copy the contents from here (update 03/25/2021: I created a gist for this because the original link went dead), replace the timezone with your timezone, and push the file to the repository.
Start pi-hole
- SSH into your pi
- Clone the repository into a folder on the pi
- Navigate to the folder that you cloned your repository into
- Uncomment and insert a value for the WEBPASSWORD
- Execute the following command to create a log file that needs to exist…
> touch ./var-log/pihole.log
- Execute the following command to start the docker container…
> docker-compose up -d
Docker should pull the image and start the container.
Configure your network or clients
So you’ve got pi-hole running on your network now, but that doesn’t do any good unless the machines on your network are requesting dns lookups from it. In the ideal scenario, you can update your network so that all devices will automatically start calling the pi for dns lookups. I’ll walk you through doing that in Ubiquiti Unifi, because that’s the network I have.
In case you can’t update your network to use a common DNS server, you can find out how to update DNS on most machines here.
Here’s how to do it in Unifi.
- Login to your controller
- Give your raspberry pi a fixed IP
- Clients
- Select your pi
- Configuration
- Network +
- Check Use fixed IP address (it should show the address it already has)
- Go to Networks > LAN (edit)
- Make the following changes:
- DHCP Name Server > Manual
- DNS Server 1 = the ip of your pi
- DNS Server 2 = 8.8.8.8 (or another DNS server you trust)
- DNS Server 3 = 8.8.4.4 (or another backup DNS server you trust)
The other DNS servers are there, just in case your pi dies or something like that and you don’t want an outage.
Update pi-hole
Stick the following in the readme.md file that you created before. That way you’ll never forget how to update pi-hole.
- SSH into your pi
- Navigate to the folder that you cloned your repository into
- Execute the following commands, individually (they’ll write some stuff to the terminal) to stop pi-hole, update it, and restart it:
> docker pull pihole/pihole > docker-compose down > docker-compose up -d
That should be everything you need to setup a pi-hole and update it when the time comes.
Hope it helps.
You must be logged in to post a comment.