Installing Docker on the Raspberry Pi

In this project, we will be showing you how to set up and test Docker on the Raspberry Pi.

Installing Docker on the Raspberry Pi

Docker is an incredibly powerful tool that provides OS-level virtualization to deliver software packages within containers.

Being in a container means the software cannot access anything that the Docker runtime doesn’t hand to it; this can help with security and resource management.

Docker allows you to deploy your software to devices in an effortless way, as everything is included in the container that the runner downloads.

Best of all, Docker does all of this while maintaining a very low overhead. Having a low overhead allows the software to run on a limited resource machine like the Raspberry Pi.

Below we will walk you through the process of installing Docker to your Raspberry Pi, as well as showing you how to test if it is running correctly.

Equipment List

Here is a list of the equipment we recommend for this Raspberry Pi Docker tutorial.

Recommended

Optional

This tutorial was tested using Raspbian Buster. If you are running an older version of Raspbian, you can use our guide to upgrade to Buster.

Docker for the Raspberry Pi has support for most versions of Raspberry Pi OS, including Bullseye, Buster and more.

Video Tutorial

The short video below will take you through the few steps to installing Docker on the Raspberry Pi. Alternatively, the entire written guide is immediately below the video.

Adblock removing the video? Subscribe to premium for no-ads.

Installing Docker to the Raspberry Pi

Thanks to a nifty install script developed by the Docker team, installing the container software is incredibly simple.

You can even complete the following steps by using an SSH connection to your Raspberry Pi.

1. Our first task is to update all our existing packages before we proceed to install Docker.

We can upgrade all existing packages by running the following two commands on the Raspberry Pi.

sudo apt update
sudo apt upgrade

2. With our Raspberry Pi entirely up to date, we can now go ahead and install Docker to the Raspberry Pi.

Luckily for us, Docker has made this process incredibly quick and straightforward by providing a bash script that installs everything for you.

You can download and run the official Docker setup script by running the following command.

curl -sSL https://get.docker.com | sh

This command will pipe the script directly into the command line. Typically it would be best if you didn’t do this; however, Docker is a trusted source.

If you are unsure about running this directly without first inspecting it, you can go directly to get.docker.com to view the script.

This script can take some time to complete as it automatically detects and installs everything it needs to run Docker on the Raspberry Pi.

Setting up your User for Docker

We need to make a slight adjustment to our user before we can start using Docker without issues.

This is to do with the way that the Linux permission system works with Docker. By default, only the Docker user can interact with Docker but there is a way to work around this.

1. Once Docker has finished installing to your Raspberry Pi, there are a couple more things we need to do.

For another user to be able to interact with Docker, it needs to be added to the docker group.

So, our next step is to add our current user to the docker group by using the usermod command as shown below. By using “$USER” we are inserting the environment variable that stores the current users name.

sudo usermod -aG docker $USER

If we don’t add our user to the group, we won’t be able to interact with Docker without running as the root user.

If you want to learn more about permissions and groups in Linux, check out our file permissions in Linux guide.

2. Since we made some changes to our user, we will now need to log out and log back in for it to take effect.

You can log out by running the following command in the terminal.

logout

3. Once you have logged back in, you can verify that the docker group has been successfully added to your user by running the following command.

groups

This command will list out all the groups that the current user is a part of. If everything worked as it should, the group docker should be listed here.

Testing the Docker Installation on Raspberry Pi

With Docker now set up on our Raspberry Pi, we should now go ahead and test to make sure it’s working.

1. To test if Docker is working, we are going to go ahead and run the following command on our Pi.

This command will tell Docker to download, setup and run a docker container called “hello-world.

docker run hello-world

2. If you have successfully installed Docker to your Raspberry Pi, you should see a message with the following text in it.

Hello from Docker!
This message shows that your installation appears to be working correctly.

Conclusion

You are now safe to start using Docker for your project, such as setting up a Docker swarm with your Raspberry Pi.

Docker containers are a great way of quickly deploying software onto your device.

To make your life easier when managing your Docker Containers, you can also set up Portainer on your Pi. Portainer is a neat piece of software that allows you to create and manage the containers within a web interface.

f you have found any issues with installing Docker, then feel free to drop a comment below.

10 Comments

  1. Avatar for Alex
    Alex on

    It was really helpfull

  2. Avatar for gingerbreadx
    gingerbreadx on

    I hit a wall big time following these instructions: the docker daemon wouldn’t start, producing all sorts of errors like:

    Job for docker.service failed because the control process exited with error code.
    See "systemctl status docker.service" and "journalctl -xe" for details.

    The solution was mercifully easy but not immediately obvious, so if anyone else experiences the same from the above, all you need do is reboot:

    sudo reboot now

    and all fixed 🙂

    1. Avatar for Wesley
      Wesley on

      Thanks, super helpful installation guide! I appreciate that you put in the part about file permissions. Those are one thing that always seems to trip me up if they’re not spelled out for me.

  3. Avatar for DeanG
    DeanG on

    What ever I try I get “Could not resolve host: get.docker.com”
    Help please!! I’m on this problem for 2 days now… 😭

    1. Avatar for Emmet
      Emmet on
      Editor

      Hi DeanG,

      That error would be caused but an issue with tire networking. In particular the DNS you are utilising.

      You can try changing the DNS provider your Raspberry pi is using to see if that resolves your problems.

      Cheers,
      Emmet

  4. Avatar for Joe
    Joe on

    is it possible to install docker with an active vpn connection?

    1. Avatar for Emmet
      Emmet on
      Editor

      Hi Joe,

      It definitely should be possible, I can’t see why a VPN connection will break it.

      Cheers,
      Emmet

  5. Avatar for Raspnoob
    Raspnoob on

    on my Raspberry pi 4, I had to do a “sudo rpi-update” before the docker engine would start. Hope this helps someone else…

    1. Avatar for Pi Noob
      Pi Noob on

      Thank you so much to Raspnoob for suggesting a firmware update – solved my problems immediately! 🙂

    2. Avatar for Bonzadog
      Bonzadog on

      That does surprise me. Did you perform a sudo apt-get update && sudo apt-get dist-upgrade before you attempted to install Docker?

Leave a Reply

Your email address will not be published. Required fields are marked *