DEV Community

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

Posted on • Edited 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

Oldest comments (67)

Collapse
 
andyraddatz profile image
Andy Raddatz

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

Collapse
 
rohansawant profile image
Rohan Sawant

I'll update the post to include this as well! Thanks! πŸ‘πŸ½

Collapse
 
rohansawant profile image
Rohan Sawant

Boom! It's done. Anything more? πŸ˜‡

Collapse
 
andrsgutirrz profile image
AndrΓ©s GutiΓ©rrez

Thanks for the post

Collapse
 
a5r0n profile image
aaron

Thanks,
also install python-dev / python3-dev

Collapse
 
rohansawant profile image
Rohan Sawant

Ah, I had this already installed, so missed it. πŸ˜…

Collapse
 
vegasbrianc profile image
Brian Christner

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

Collapse
 
rohansawant profile image
Rohan Sawant • Edited

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.

Collapse
 
vegasbrianc profile image
Brian Christner

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

Thread Thread
 
rohansawant profile image
Rohan Sawant

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.

Thread Thread
 
vegasbrianc profile image
Brian Christner

This is specific to ARM Docker deployments. The Ubuntu deployments in the Cloud don't seem to have this issue.

I found people having the similar issue after installing docker-compose - github.com/docker/docker-py/issues...

Collapse
 
dbrosy profile image
dbrosy

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

Collapse
 
kampen_rob profile image
Rob van Kampen • Edited

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?

Collapse
 
descansodj profile image
Nazareno DeFrancesco

This helped me solving this problem: raspberrypi.org/forums/viewtopic.p...

Collapse
 
rohansawant profile image
Rohan Sawant

Hey Rob,

That is super weird. I just tried this with a fresh installation and I did not have any issues.

Does rebooting after installing docker help?

Collapse
 
eriksneff profile image
Erik Neff • Edited

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!

Collapse
 
rohansawant profile image
Rohan Sawant

Oh, on Ubuntu 19?

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

Collapse
 
rohansawant profile image
Rohan Sawant

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.

Collapse
 
aheil profile image
Andreas Heil

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!

Collapse
 
unfor19 profile image
Meir Gabay

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

Collapse
 
ask_dba profile image
Alkin Tezuysal

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.

Collapse
 
ask_dba profile image
Alkin Tezuysal

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