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

Rohan Sawant @rohansawant

About: Hi! I'm Rohan, a Full Stack Software Engineer, with a background of working with Deep Learning and AI, who loves to use his skills to create products that are at the intersection of all of these!

Location:
Mumbai, India
Joined:
Jul 11, 2018

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

Publish Date: Oct 12 '19
192 67

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

Comments 67 total

  • Andy Raddatz
    Andy RaddatzNov 8, 2019

    Thanks for this, but I also had to install libssl-dev before the final sudo pip install docker-compose worked

    • Rohan Sawant
      Rohan SawantNov 9, 2019

      I'll update the post to include this as well! Thanks! 👍🏽

      • Rohan Sawant
        Rohan SawantNov 9, 2019

        Boom! It's done. Anything more? 😇

  • Andrés Gutiérrez
    Andrés GutiérrezNov 11, 2019

    Thanks for the post

  • aaron
    aaronNov 15, 2019

    Thanks,
    also install python-dev / python3-dev

    • Rohan Sawant
      Rohan SawantNov 15, 2019

      Ah, I had this already installed, so missed it. 😅

  • Brian Christner
    Brian ChristnerNov 18, 2019

    It seems a problem with the docker python client. After running docker-compose for the first time. You get the error ImportError: No module named ssl_match_hostname on init

    The fix is cp -r /usr/local/lib/python2.7/dist-packages/backports/ssl_match_hostname/ /usr/lib/python2.7/dist-packages/backports

    • Rohan Sawant
      Rohan SawantNov 19, 2019

      Hmm, this is weird did you try to install it with Python 3?

      Python 2 support ends next year.

      Update, in the next few weeks, I'll rewrite this and try again on a fresh installation that should help me find the errors.

      • Brian Christner
        Brian ChristnerNov 19, 2019

        I was just using the standard installers as listed in your instructions (which are great BTW). Everything from first glance still uses Python2.

        • Rohan Sawant
          Rohan SawantNov 19, 2019

          Yeah, you are correct, I just re-read my own post and yep everything seems to be using Python 3 😅

          Please disregard my last comment.

          I'll update the post and fix the remaining issues soon, that should help with my confusion.

          Just out of curiosity how did you manage to fix the problem? By copying the dependency? I haven't seen this solution ever before.

    • dbrosy
      dbrosyNov 21, 2019

      this might be a better option.

      sudo apt-get remove python-configparser
      
      Enter fullscreen mode Exit fullscreen mode

      After removing configparser docker-compose starts as expected.
      I removed after installing compose via pip but noted an error related to configparser at end of install so this might be better run after dependencies but before compose. This part I haven't tried

  • Rob van Kampen
    Rob van KampenNov 30, 2019

    Hi Rohan,

    after step 1 i got the message back: status = stable.
    When i enter step 2 ... i got back: usermod: group 'docker' doesnt exist

    Please can you help me?

  • Erik Neff
    Erik NeffNov 30, 2019

    Thx for this post, Rohan! One possible thing to add - when I ran the command: sudo pip install docker-compose on my Raspberry Pi 4 running Ubuntu 19.10, I got the error:

    ERROR: Cannot uninstall 'PyYAML'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

    After reading this thread - stackoverflow.com/questions/499115... - I was able to install docker-compose by adding the ignore-installed flag like this:

    sudo pip install docker-compose --ignore-installed PyYAML

    Note that during the install, I did see these 2 errors:
    ERROR: launchpadlib 1.10.7 requires testresources, which is not installed.
    ERROR: docker-compose 1.25.0 has requirement PyYAML<5,>=3.10, but you'll have pyyaml 5.1.2 which is incompatible.

    but that didn't stop docker-compose from installing successfully, and now I have:

    ubuntu@ubuntu:~$ docker-compose --version
    docker-compose version 1.25.0, build b42d419

    and I just manually ran sudo pip install testresources after. Hope this helps!

    • Rohan Sawant
      Rohan SawantDec 3, 2019

      Oh, on Ubuntu 19?

      I had not thought it would work with that. Cool that you manage to get it working!

  • Rohan Sawant
    Rohan SawantDec 3, 2019

    I just tested everything on a fresh Raspbian Buster build on a Raspberry Pi 3 B+ and it indeed needed a few changes.

    sudo apt-get remove python-configparser

    Thanks to @dbrosy and @vegasbrianc for pointing it out.

  • Andreas Heil
    Andreas HeilDec 27, 2019

    Thanks for this hint! I literally tried each and every approach I found. Installing the dependencies fixed my issue with docker-compose 1.25 on Raspberry Pi 4 and Ubuntu Server on it!

  • Meir Gabay
    Meir GabayJan 3, 2020

    Tested on

    Model: Raspberry Pi 4 Model B 4GBRAM
    MicroSD: Sandisk 32GB
    OS: Raspbian Buster with desktop
    Flashed OS App: Balena Etcher

    Thank you Rohan

  • Alkin Tezuysal
    Alkin TezuysalJan 6, 2020

    My docker-compose step fails as follows;
    Exception: Version mismatch: this is the 'cffi' package version 1.13.2, located in '/tmp/pip-build-mJ6FCD/pynacl/cffi-1.13.2-py2.7-linux-armv7l.egg/cffi/api.pyc'. When we import the top-level '_cffi_backend' extension module, we get version 1.9.1, located in '/usr/lib/python2.7/dist-packages/_cffi_backend.arm-linux-gnueabihf.so'. The two versions should be equal; check your installation.

    Any help appreciated.

    • Alkin Tezuysal
      Alkin TezuysalJan 6, 2020

      sudo pip3 install cffi==1.13.2 solved but there are other dependencies.

  • fred-c1
    fred-c1Jan 16, 2020

    Thanks.
    Tested today.
    Raspberry pi 3B+ with Raspbian Buster Lite

    I had to switch to python3/pip3 to install docker compose.
    The message just before the error was:
    setuptools requires Python '>=3.5' but the running Python is 2.7.16

    Solution:
    1 = make python3 the default python => search google
    2 = sudo apt-get install -y python3-pip "3" !!!
    3 = sudo pip3 install docker-compose "3" !!!

    • Marcel Zuidwijk 
      Marcel Zuidwijk Jan 19, 2020

      Yep, got this error too and that indeed was the solution. The strange part is that it did worked, till about one or two weeks ago. Now I use this:

      $ curl -sSL get.docker.com | sh
      $ sudo usermod -aG docker pi
      $ sudo apt-get install libffi-dev libssl-dev
      $ sudo apt-get install -y python3 python3-pip
      $ sudo apt-get remove python-configparser (apparently this isn't installed by using my commands on a clean install)
      $ sudo pip3 install docker-compose

      • Rohan Sawant
        Rohan SawantMar 13, 2020

        Updated the post to reflect this. Thanks!

  • svanzon
    svanzonJan 18, 2020

    Hi, thanks for you post.

    I'm starting to work with Docker and Docker-compose but can't install the docker-compose.

    My configuration is:

    • RaspberryPi 3+
    • Raspbian Full Stretch and Buster (tried both with a clean install)

    The hello-world docker runs without errors. So docker is installed.

    But with the last command "sudo pip install docker-compose" There is an error end I don't know how too solve it. Looked around at the internet and trying Stretch and Buster version of Raspbian. Can you help me.

    setuptools requires Python '>=3.5' but the running Python is 2.7.16
    
    Command "/usr/bin/python -m pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-1XaNDC --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple --extra-index-url https://www.piwheels.org/simple -- setuptools>=40.8.0 wheel "cffi>=1.1; python_implementation != 'PyPy'"" failed with error code 1 in None
    
  • Thordur Thordarson
    Thordur ThordarsonFeb 1, 2020

    Finally a solution that works for me after looking everywhere. Thank you, sir!

  • Rick Broberg
    Rick BrobergFeb 25, 2020

    If you amend step 2 to include

    newgrp docker

    then you don't need to reboot or use 'sudo docker' while you're in that shell.

    Also, if you amend step 4 to include '-y' in your 'apt-get install' lines it is more friendly to copy/paste. Everybody is going to answer 'y to the installation question anyway.

  • Ben Mitchinson
    Ben MitchinsonMar 2, 2020

    Worked on first try as of March 2020 Rasp Buster Lite, thank you!

    Also, the build step for bdist_wheel to run setup.py takes a pi 3 b+ like 12 minutes, so know that it's not broken if that's taking a while. CPU gets pretty hot, recommend rebooting and letting it cool for a while.

  • Hans Bakker
    Hans BakkerMar 19, 2020

    Out of curiosity, why did you choose to install from scratch, rather than using a Raspberry Pi image from Hypriot?
    What are the pros / cons?
    What is more reliable / maintainable?

    You can read something about Hyrpiot OS on blog.hypriot.com/getting-started-w...

    • Rohan Sawant
      Rohan SawantMar 20, 2020

      Huh? Honestly. I instinctively googled "how to install docker on the Raspberry Pi" and most of the other guides mentioned some iteration of the steps in this article but many of them didn't work.
      So, when I thought of creating a simple guide that actually worked, those were the steps that I chose to follow.

      But, if you know you want to run Docker right from the beginning, maybe Hyrpiot is a better option. :) I already had other projects running on the Pi and I was too lazy to reflash.

  • tanakornp
    tanakornpApr 6, 2020

    Thx for your article.
    I wasted a full day try to get docker-compose up and running on my Pi4 while it took me only few minutes to get it works on Ubuntu VM.
    In Ubuntu VM, "apt-get install docker-compose" did the job but some how for Pi it did not :\

  • Bobby
    BobbyApr 6, 2020

    Great tutorial!

    I actually have a short video on how to do that as well:

    youtube.com/watch?v=zvs-7GRKN38

  • muyangren1880
    muyangren1880Apr 7, 2020

    Hi , I'm shepherd ,
    I used the "2019-09-26-raspbian-buster-full.img" raspberry pie image(3B+).When I used this image last year, I could install docker normally.Today, I reinstalled the system and encountered a problem while installing docker.
    First:
    1.sudo apt-get update && sudo apt-get upgrade
    No problem
    2.curl -fsSL get.docker.com -o get-docker.sh
    No problem
    3.sudo sh get-docker.sh
    error:Essential packages were removed and -y was used without --allow-remove-essential.
    I've updated Python to 3.6;
    The problem has always been. I don't know what happened
    I hope you can help me.

    • Rohan Sawant
      Rohan SawantApr 7, 2020

      Hmm, so this is what I can do. This weekend, I'll try the Docker installation on a fresh newest version of Raspbian and see if it's still working out of the box.

      That should help you 🤔

  • Saumyadip Biswas
    Saumyadip BiswasMay 7, 2020

    curl -sSL get.docker.com | sh , This curl will not work with ubuntu 20.04 server running on pi
    $ sudo apt update && sudo apt upgrade -y
    $ curl -sSL get.docker.com | sh
    $ sudo usermod -aG docker pi
    $ sudo apt install libffi-dev libssl-dev python3 python3-pip

    • Rohan Sawant
      Rohan SawantMay 7, 2020

      Oh, I had tested everything with Raspbian.

      Btw, How is the Ubuntu support on the RPi? Is it worth moving to Ubuntu from Raspbian? 🤔

  • Pavel Burgr
    Pavel BurgrMay 14, 2020

    Hi, thanks for nice post. In case you want to get Raspi image with preinstalled docker in one step, check this out: device.farm. Beside the Linux image, you can also simply manage your docker over internet or access your container's services from internet.

  • klo2k
    klo2kMay 24, 2020

    On Ubuntu 20.04 raspberrypi, this also works:

    apt install --yes python3-paramiko
    pip3 install docker-compose
    
    Enter fullscreen mode Exit fullscreen mode
  • TheDynomike
    TheDynomikeJun 23, 2020

    This works on

    PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"

  • Cameron
    CameronJul 4, 2020

    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.

    • Rohan Sawant
      Rohan SawantJul 5, 2020

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

  • Anup Ramachandran
    Anup RamachandranJul 23, 2020

    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?

  • bertfw
    bertfwAug 10, 2020

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

    github.com/pypa/pip/issues/5599

  • TeeSo di Carlo Oldani
    TeeSo di Carlo OldaniOct 27, 2020

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

    • Rohan Sawant
      Rohan SawantOct 29, 2020

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

  • Phil Chen
    Phil ChenOct 30, 2020

    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!

    • Rohan Sawant
      Rohan SawantNov 3, 2020

      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!!

  • LT "syreal" Jones
    LT "syreal" JonesDec 10, 2020

    Very helpful, thank you!

  • William Bell
    William BellJan 3, 2021

    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.

    • William Bell
      William BellJan 4, 2021

      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...

      • Birger Luecht
        Birger LuechtJan 28, 2021

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

        • William Bell
          William BellFeb 2, 2021

          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..

      • Robert Bernstein
        Robert BernsteinFeb 21, 2021

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

        • Robert Bernstein
          Robert BernsteinFeb 21, 2021

          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.

          • William Bell
            William BellFeb 22, 2021

            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

  • reedcons
    reedconsJan 5, 2021

    Hi,
    if you add

    su - pi

    after

    sudo usermod -aG docker pi

    you dont need reboot

  • Brian Scott
    Brian ScottMar 4, 2021

    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.

  • Laura Seidler
    Laura SeidlerMar 10, 2021

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

  • Asure
    AsureApr 19, 2021

    thnk you

  • Mariusz Krezel
    Mariusz KrezelNov 10, 2021

    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

  • Mariusz Krezel
    Mariusz KrezelNov 10, 2021

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

  • swinster
    swinsterDec 3, 2022

    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.

  • Thomas Schewe
    Thomas ScheweFeb 5, 2023

    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.

Add comment