So, you've just gotten your raspberry pi, I know I just did at least, and you want to set it up with docker so you can bring all of your favorite applications to this powerful piece of technology. Well then you're in the right place I'll be showing you how to setup raspberry pi with docker using raspbian os
Updating your raspberry pi
To start off update your raspberry pi to the latest version using the following command
The following command simply updates your raspberry pi to the newest version that way you won't have any issues. The command can take a couple minutes to an hour or so depending on your network speed and how much you have to update
When you run the command the output should look something along the lines of this
How to upgrade Pi-hole. 1) Logon to your server and open terminal. 2) Navigate to the below directory (used in my installation guide, referenced at the start of this guide): cd /home/pi/pi-hole. 3) Download the latest pi-hole image by running the below command: docker image pull pihole/pihole:latest. 4) When the download is complete, run the. How to setup pi-hole and Docker? Open your terminal and Start docker. Sudo systemctl start docker. Enter the command to download pihole from docker hub. Sudo docker pull pihole/pihole. Step 2: Skip this if you are not using Ubuntu. Sudo systemctl stop systemd-resolved.service. Sudo systemctl disable systemd-resolved.service. If you get this output, it means that your Docker setup is completed, yay! Now is the time for the real stuff: running the Pi-hole. Docker allows us to control a remote Docker machine by running our regular Docker commands with a special env variable called DOCKERHOST. So, let’s start by defining this environment. Pi-Hole is a free and open-source ad-blocker. The source code is available on GitHub, and can be installed on Raspberry Pi OS with one command line: curl -sSL sudo bash. In this post, I’ll start by introducing Pi-Hole, then show you how to install it and configure it on your network. The easiest way to install PiHole is to run it in Docker. It makes it easy to update or uninstall PiHole. It also lets you keep the parts of the network isolated for security. Even the Raspberry Pi can be replaced in just a few minutes. Plus, the configuration can be saved into a networked drive.
After you've updated your raspberry pi it's time to install docker, once again it's quite simple to do so just run the command
which will get the docker install script for docker if you want to run the test branch of docker use the command
You can verify that you've downloaded the script by running
ls and verifying the output shows either
Once the file is downloaded you want to run it. Execute the script by running the following command
Now if it does not run the script you will have to run
sudo chmod +X ./get-docker.sh This just gives the script the E(x)ecute tag hence the +. Afterward, re-run
It will then attempt to install docker automatically for you, you can for the most part safely ignore all the stuff that comes up in the terminal as it's just the command it's doing
The output looks something like this
Verifying the install
Once the command is done running you can verify that docker is installed by running
Which should return something along the lines of this
If it returns
-bash: docker: command not found restart your raspberry pi and attempt to run the command again. If it still doesn't work run the install script again
Next up we'll be going through how to make docker work without adding sudo first, if you're not interested in that you can skip over that section and move straight to Hello-World
To make docker run without root you need to create a user group to access the docker container you can do such by running the following command
replace <user> with your username which by default is pi
For the changes to take effect you have to log out and log back into your account or you can optionally run this command
Once again replace <user> with your username
For the sake of tutorial, I'll just be running the reboot command which restarts the raspberry pi
Note: if you decide to do it this way you have to ssh into your raspberry pi again
As with all programming languages or tools nowadays the first thing you do is Hello World so let's get to it
To run the hello world docker container simply write
If all is well it should return this
and that's it. Well done! now you're well on your way to learning docker
Setting up docker-compose (optional)
So the new standard nowadays is setting up docker containers using docker-compose
Since the docker install doesn't come with this you have to install this manually
To run docker-compose you need python3You can get it by running the following commands
After you've installed the dependencies above you can install using pip3 by running this command
and that's it now you can use docker-compose in addition to docker! Here's me attempting to setup pi-hole using docker-compose
Recently I moved from my old PI3B to a Intel NUC i3 as my 'Home Server' enough power to run all my local services and still not so wasteful in terms of Power consumption and Space requirement like a 'real' Server and it is fanless.
Due to the gained CPU Power and a bit more flexibility over my previous used pfBlockerNG, I decided to give pihole a try. If you do not Know Pihole, in short: A local GUI Managed Filtering DNS Cache using Blocklists to block Malware/Ads/phising/... you could say a 'uBlock Origin' server based.
docker-compose and piholeInstead of Running the pihole directly on my Ubuntu LTS I decided to go the Docker way, should give me a much easier way to update it. Instead of the 'manual' docker way I prefer to go with docker-compose. That's a tool for easily manage, upgrade and deploy docker containers / images by just one Config file. So what you need to do is actually very simple. First install docker and docker-compose package on your system, in Ubuntu this is:Docker-compose is handling everything for you, only thing you need to tell is what to do exactly in a YML Config. This is mine:
docker-compose.ymlSo to get started best is to create a new user named pihole and in it's homedir create above docker-compose.yml after that make sure you are in the same directory (cd /home/pihole) and you can install everything with the command docker-compose up
You should now see docker-compose downloading and installing the new container and spawning it, when it's done check the pihole admin interface at /admin in your webbrowser and use the previous set password to login. If everything works as intended you can use your pihole local IP as DNS Server for your clients. In my case I do not use piholes DHCP Server Feature, instead I let my router (pfSense) distribute my piholes IP as DNS to my LAN Clients and created some rules to forbid all other tcp/udp Port 53 Outgoing Traffic for LAN Clients with exception the pihole itself.
To start it in background you can use docker-compose start command, also make sure that docker itself is auto started after boot by systemctl enable docker
Useful is the command docker-compose logs to see the recent logs of the composer and container.
Setup Pi Hole Docker Tool
Another useful thing is adding a Alias to your bash aliases. If you run pihole without a container you can use the pihole command to see the live log or issu some commands like adding Whitelist entries from CLI and so on. In a docker conatiner you can't run the pihole binary just in the cli, you need to run it thorugh docker exec. As a Shortcut you can add this to your ~/.bash_aliases
Ultimate Network Monitoring Solution With A Raspberry Pi Using DockerAfter relogin to your shell you now have the direct pihole cli available. For example you can now tail the pihole live log with pihole -t
So basically thats it. Having a pihole Running in 5 minutes. Next thing to add is full internal IPv6 Support.
Update: I was asked what List's I can recommend for pihole - well that is a very personal decission. Most ppl do not need the China List for Example, but because we use a lot of chinese websites here it is a welcome addition for me. I can only give one Tip, whatever lists you choose - have a look that they are regulary maintained and old non existing hosts removed. Here is a gist with my current (tbc) used Lists.