Raspberry Pi

Install Docker on a Raspberry Pi

Run Docker on your Raspberry Pi to maximize the resources and performance of your Pi!

How to install Docker on a Raspberry Pi

So, you’re thinking about installing Docker on your Raspberry Pi, huh? Well, if that’s the case, then you have come to the right place. I LOVE Docker, especially on the Raspberry Pi and I’m excited to show you how to get it installed.. In this tutorial, we’ll install Docker on a Raspberry Pi 4, but you can do this on any Pi you choose.

What is Docker?

Docker is a software that can be installed on a variety of devices, including various Linux distributions, Windows, and Mac OS. Docker is an open platform for developing, shipping, and running applications. It enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.

What does this mean for you? By creating docker configuration files you can easily take one container on one client and put it on another with a simple copy and paste. If you download a Docker image, all the dependencies are automatically installed. The dependencies are separate from the root system so if you delete an image the dependencies are also gone. 

Why Should you install Docker on a Raspberry Pi?

This is a pretty common question. Using Docker allows you to keep your programs completely isolated from your system. This helps avoid conflicting service issues. It allows better security for applications such as VPN and torrent clients by better protecting again IP leaks. 

Low-Resource Utilization

Using Docker also improves resource utilization and what lower end clients, such as a Raspberry Pi’s, can do. For example, using Docker, you can successfully create a Raspberry Pi home-server running Plex, Samba, VPN, qBittorrent, Rpi-Monitor, and Pi-hole with very low resource utilization, see below screenshots. 

Temp Log of Raspberry Pi Running Docker as at-home Server
CPU Load Graph of Raspberry Pi Running Docker as at-home Server

Ease of Use

Ease of use is something that is incredibly important in today’s age. This is especially true for beginners who may not know exactly what they are doing. You can find pre-built commands to install images and get them working on Docker Hub. Docker also offers the ability to start, stop, and restart containers with ease using simple commands like you see below.

					docker start container_name
docker stop container_name
docker restart container_name

So you've decided you want to install Docker on a Raspberry Pi

Let’s continue with the process of actually getting Docker installed on your Raspberry Pi.  You can find a step-by-step tutorial below. Please remember to read each step carefully and if you have questions at all, you can visit our Contact page. We’d love to help you troubleshoot potential issues!

Everything you need

  • Raspberry Pi 4GB
  • On/Off Switch
  • Power Supply
  • Aluminum Heatsinks

Get it here!

Step 1: Make sure everything is up to date

Make sure that before you go any further you update and upgrade all the programs installed on your Raspberry Pi. This will help prevent potential issues with required dependency errors. To do this, run the below commands.

					sudo apt update && sudo apt upgrade

Step 2: Check to see if you have any old Docker versions installed

It’s possible that you could have old versions of Docker installed on your device. You will want to be sure to remove any of these to avoid potential issues.

					sudo apt remove docker docker-engine containerd runc
sudo apt autoremove

Step 3: Install the required dependencies

In order to install Docker you’re going to have to install the programs that Docker depends on to run.

					sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release

Step 4: Add Docker's official GPG key and Repository

The next step in the process is going to be adding Docker’s official GPG key. You will also add the Docker repository. This is going to allow you to install Docker along with installing updates.

					curl -fsSL | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
  "deb [arch=armhf signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Step 5: Install Docker on Raspberry Pi

In this step we’ll finally be getting to the fun stuff, installing the Docker Engine. Update your system again now that we have added a new repository!

					sudo apt update
sudo apt-get install docker-ce docker-ce-cli

Step 6: Test your installation

Now that we have successfully installed Docker, we’ll want to test it to make sure that everything is operating correctly. To do this, input the following command into your command line. This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

					sudo docker run hello-world

Step 7 (Optional): Post-installation steps

As of now you have Docker installed, and you can install images and create containers. However, there are a couple of other things that you should do for a better experience with Docker.

Manage Docker as a non-rootuser

Obviously, you don’t want to type “sudo” every time that you want to manage Docker. To get rid of this follow the below steps. If the hello-world docker image runs, everything is working correctly.

					sudo groupadd docker
sudo usermod -aG docker pi
newgrp docker 

docker run hello-world

Configure Docker to start on boot

If you don’t want to start Docker manually every single time you turn on your device, you’ll want to follow the below steps.

					sudo systemctl enable docker.service
sudo systemctl enable containerd.service

Congratulations, you've learned how to install Docker on a Raspberry Pi!

Congratulations, you’ve successfully installed Docker. What are the next steps? Head over to Docker Hub to see what amazing applications people have created.

We hope you enjoyed this article, if you did make sure to share it!

Get tutorials delivered to your inbox weekly.

More Posts

2 replies on “Install Docker on a Raspberry Pi”

Since I got started with my first Raspberry Pi about a week ago this is the first time I’ve found a tutorial that appears to be accurate and gives me actually working results. Thank you very much.

Maybe you could have a look at “Step 3: Install the required dependencies”. Somehow, there’s no “COPY” button in that code section.

Leave a Reply

Your email address will not be published.