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
Top comments (67)
This works on
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
Thanks so much! Worked on Raspberry Pi 4
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.Ah, thanks, man! I am glad it worked!
On Ubuntu 20.04 raspberrypi, this also works:
Ah, thanks! 👍🏽 🙂
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
this might be a better option.
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
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.
I was just using the standard installers as listed in your instructions (which are great BTW). Everything from first glance still uses Python2.
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.
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...
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" !!!
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
Updated the post to reflect this. Thanks!
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.
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.
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...
Thank you, @william bell! That did the trick!
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.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
Thanks for the outline of step by step commands. This worked for me also on RPI3
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..
Tested on RetroPi 4, I was originally getting
sub-process /usr/bin/dpkg returned an error code (1)
right after installing docker using thecurl -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 bydocker run hello-world
would give you error message about the access denyhello-world
steps and the rest!Thanks Rohan for this awesome guide!
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!!
Thanks for this, but I also had to install
libssl-dev
before the finalsudo pip install docker-compose
workedI'll update the post to include this as well! Thanks! 👍🏽
Boom! It's done. Anything more? 😇
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.