DEV Community

Cover image for Installing Docker and Docker Compose on the Raspberry Pi in 5 Simple Steps
Rohan Sawant
Rohan Sawant

Posted on • Updated on

Install Docker on Raspberry Pi Installing Docker and Docker Compose on the Raspberry Pi in 5 Simple Steps

You know what Docker is. You know what a Raspberry Pi is. Let me make sure they hit it off together. 😎🤝🏽

This is probably one of the quickest and easiest ways to get Docker and Docker Compose running on the Raspberry Pi.
(Tested with Raspberry Pi B+ Rev 1.2 and Raspberry Pi 4)

After searching the Inter-Webs for hours and having several things not work for me, I decided something needed to be done about it.

Steps

1. Install Docker

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

2. Add permission to Pi User to run Docker Commands

sudo usermod -aG docker pi

Reboot here or run the next commands with a sudo

3. Test Docker installation

docker run hello-world

4. IMPORTANT! Install proper dependencies

sudo apt-get install -y libffi-dev libssl-dev

sudo apt-get install -y python3 python3-pip

sudo apt-get remove python-configparser

5. Install Docker Compose

sudo pip3 -v install docker-compose

Boom! 🔥 It's done!

Important Notice about Docker on the Raspberry Pi

Raspberry Pis use the ARM architecture, and as a result, won't be compatible with all containers out of the box. Images will need to be built from an ARM base image. But, most of these images can easily be found on Docker Hub

Latest comments (67)

Collapse
 
thosch66 profile image
Thomas Schewe • Edited

Since April 26, 2022 the recommended way to use Docker Compose is the subcommand docker compose. The subcommand can be added with the plug-in docker-compose-plugin.

docker-compose is deprecated.

Collapse
 
swinster profile image
swinster

FWIW, I was trying to get docker running on a really old Pi v1 B+. The info regarding Docker Compose in this article is now out of date. Docker Compose v2 no longer used python, but the compose plugin installed directly as a package when running the main install script. So, there is no need to update python libraries or install using pip.

It does look like docker runs on this Pi, albeit it looked like it failed to start initially. Rebooting the Pi seems to allow the service to start.

Collapse
 
greenfrogsb profile image
Mariusz Krezel

Great article, if anyone would like to automate installation process and deploy few container quickly, check out this method:
greenfrognest.com/lmdsondocker.php

Collapse
 
greenfrogsb profile image
Mariusz Krezel

Great article, if anyone would like to automate installation process and get some container installed quickly, check out my script here:
greenfrognest.com/lmdsondocker.php

Collapse
 
asureking profile image
Asure

thnk you

Collapse
 
lauraseidler profile image
Laura Seidler

On a Raspberry Pi 4, with Raspbian Lite, just running apt install docker-compose after installing docker worked just fine for me

Collapse
 
bscott profile image
Brian Scott

Make sure you scan any images coming from Docker Hub, Reports find that 49% of the images have critical vulnerabilities. Use something like Clair to scan first.

Collapse
 
reedcons profile image
reedcons

Hi,
if you add

su - pi

after

sudo usermod -aG docker pi

you dont need reboot

Collapse
 
wmbell65 profile image
William Bell • Edited

Hi everyone,
I am trying to duplicate this on a set of PI 2B (v1.1) and a Pi 3B. I am completely new to Docker and thought this would be a good way to get started. I am setting up the Pi 3B as the masternode and 8 PI 2Bs as nodes for a docker swarm. I am running all nodes with the latest Raspian OS freshly installed on SD cards. I am running into an issue with the very first step.. it looks like there is an error in the source script, so am looking to see if this can be broken apart.. Any suggestions would be helpful.

Collapse
 
wmbell65 profile image
William Bell

Hi everyone,
I managed to get things sort of sorted out:
1) I ran 'sudo apt-get remove docker*' on all nodes.
2) I then removed /etc/docker /var/lib/docker /etc/init.d/docker /run/docker on each node.
3) I ran 'sudo apt-get clean' on all nodes
4) rebooted all nodes

Starting from scratch I downloaded the get-docker.sh and copied it to each node and ran the following:
sudo sh get-docker.sh
sudo usermod -aG docker pi
sudo systemctl start docker.service
sudo systemctl enable docker.service
docker info
docker run hello-world

The next step was to run 'docker init swarm' on one of the nodes to create the manager node. This looks to have completed properly as I got 'swarm initialized....'

At this point, the responsiveness of the node fell through the floor.. top shows CPU 98% idle but keystrokes etc are delayed by 30-40 seconds. I am thinking maybe memory?? but am not sure what the next step would be after this...

Collapse
 
robertbernstein profile image
Robert Bernstein

Thank you, @william bell! That did the trick!

Thread Thread
 
robertbernstein profile image
Robert Bernstein

I may have spoken to soon. It finished running sudo sh get-docker.sh, which it hadn't before, but it still fails to start Docker Application Container Engine.

Thread Thread
 
wmbell65 profile image
William Bell

I switched over to Ubuntu and not only did Docker install, I got Kubernetes installed and working as well.. I had to try a couple of minor things, but mostly missing packages

Collapse
 
pachangadad profile image
Birger Luecht

Thanks for the outline of step by step commands. This worked for me also on RPI3

Thread Thread
 
wmbell65 profile image
William Bell

As an FYI.. the whole issue of the master node hanging went away when I switched from Raspberry Pi OS to Ubuntu 20 server.. I even managed to get kubernetes installed..
What made this interesting was that the master is a Pi 3b with an ARM7 V4 while the rest are Pi 2B+ with ARM7 v5..

Collapse
 
syreal17 profile image
LT "syreal" Jones

Very helpful, thank you!

Collapse
 
icloudphil profile image
Phil Chen

Tested on RetroPi 4, I was originally getting sub-process /usr/bin/dpkg returned an error code (1) right after installing docker using the curl -sSL https://get.docker.com | sh after a whole bunch of the google search, I landed. Just want to share the error I got was simply resolved by

  1. continue to follow those 5 simple steps
  2. skip docker run hello-world would give you error message about the access deny
  3. restart your raspberry pi 4
  4. come back and continue with the hello-world steps and the rest!
  5. it simply just worked!

Thanks Rohan for this awesome guide!

Collapse
 
rohansawant profile image
Rohan Sawant

Ah, thanks man. I'll add a note to restart the device if you see any errors. It's people like you who help keep this guide updated!!

Collapse
 
teeso profile image
TeeSo di Carlo Oldani

tested on raspberry A+ with raspbian os lite aarch64 ... works truly fine ...

Collapse
 
rohansawant profile image
Rohan Sawant

A+ too? Could not have expected that! Thanks for reading, mate!

Collapse
 
bertfw profile image
bertfw

sudo should never be used with pip. Please read the reasoning here:

github.com/pypa/pip/issues/5599

Collapse
 
anupcoded profile image
Anup Ramachandran

Getting this error after installing on Rpi. Any idea.

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Collapse
 
cmrn profile image
Cameron

Thanks so much! Worked on Raspberry Pi 4

sudo apt-get -y install libffi-dev libssl-dev python3-dev python3 python3-pip
sudo pip3 -v install docker-compose
Enter fullscreen mode Exit fullscreen mode

After a fresh install, firmware and distro upgrade, docker-compose seemed to take quite a while to finish. Added the -v verbose flag to make sure the install wasn't stuck.

Collapse
 
rohansawant profile image
Rohan Sawant

Ah, thanks, man! I am glad it worked!