08 Jan 2022
- Comments (0)
How to set up Docker on a Raspberry Pi 4
Docker is a great tool that makes managing and running web services easy and it is very popular among developers because you can run services that only run within its container. This means that you can multiple Nginx proxies without interfering with each other, or multiple databases.
One of the biggest plusses with Docker is that your developer environment will function exactly as it would on your production server. The old-fashioned way you wouldn't be sure that things would work exactly the same way because your computer would run an operating system and your production server another or maybe you were running a different version than your production server.
The list of benefits is long, and we won't be going through them because it is time to install Docker on your Raspberry Pi!
How to install Docker on Raspberry Pi 4
In this tutorial, we will be installing and running Docker on your Raspberry Pi 4. Before beginning the tutorial you need to have a few things set up to make sure all the steps can be achieved:
- Raspberry Pi running Raspbian
- SSH should be enabled
- It should have its own IP address on your home network.
Step 1: Update and upgrade your Raspberry Pi
The first step is to make sure your Raspberry Pi is updated with the newest packages. You can do that by running the line below:
sudo apt-get update && sudo apt-get upgrade
The script above will first update all of the packages on your Raspberry Pi and then afterward install them.
Step 2: Download the installer and install Docker
Now that your Raspberry Pi is totally updated we are ready to install Docker. Copy/paste the line below to first download the installer:
curl -fsSL https://get.docker.com -o get-docker.sh
After the script has been downloaded you run the following line in your console to start the installer:
sudo sh get-docker.sh
Step 3: Check the Docker version on your Raspberry Pi
Now that Docker has been successfully installed on your Pi, you can do a simple check to ensure you have the correct version installed. To check the current version of Docker please use the line below:
sudo docker version
This line will output the Docker version along with other useful information. If you get an error here, Docker isn't installed correctly and you should start over from step 1.
Step 4: Create a non-root user to use with Docker
Normally it is only users with root privileges who can run Docker containers, but you can also create another user and give it privileges to run and administrate Docker containers.
In the following example, we are giving the user Pi the necessary privileges to run and administrate Docker containers:
sudo usermod -aG docker pi
You don't have to create a user, especially for Docker, since all users can administrate Docker containers. Non-root users without Docker privileges have to use sudo to start, stop and delete containers.
Step 5: Run the hello-world image
Now that Docker has been installed and you have created a user for Docker, you can try to run the hello-world image to see if everything is working as it should. Use the following line to download and run the image:
docker run hello-world
Install Portainer to visually manage your Docker containers
To make it easier for you to manage your Docker images and containers, you can install Portainer which is a free service that allows you to visually manage all your instances through a web interface. With Portainer you can also change settings on your containers, group them, and much much more.
We have made an easy tutorial on how to install and get started with Portainer which you will find right here: How to install Portainer using Docker on your Raspberry Pi.