Docker comes to Raspberry Pi

If you’re not already familiar with Docker, it’s a method of packaging software to include not only your code, but also other components such as a full file system, system tools, services, and libraries. You can then run the software on multiple machines without a lot of setup. Docker calls these packages containers.

Mayview Maersk by Flickr user Kees Torn

Mayview Maersk by Flickr user Kees Torn

Think of it like a shipping container and you’ve got some idea of how it works. Shipping containers are a standard size so that they can be moved around at ports, and shipped via sea or land. They can also contain almost anything. Docker containers can hold your software’s code and its dependencies, so that it can easily run on many different machines. Developers often use them to create a web application server that runs on their own machine for development, and is then pushed to the cloud for the public to use.

While we’ve noticed people using Docker on Raspberry Pi for a while now, the latest release officially includes Raspbian Jessie installation support. You can now install the Docker client on your Raspberry Pi with just one terminal command:

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

From there, you can create your own container or download pre-made starter containers for your projects. The documentation is thorough and easy to follow. You can also follow this Pi-focused guide by Docker captain Alex Ellis.

Docker Swarm

One way you can use Raspberry Pi and Docker together is for Swarm. Used together, they can create a computer cluster. With Swarm containers on a bunch of networked Raspberry Pis, you can build a powerful machine and explore how a Docker Swarm works. Alex shows you how in this video:

Docker Swarm mode Deep Dive on Raspberry Pi (scaled)

Get all the details @ http://blog.alexellis.io/live-deep-dive-pi-swarm/

You can follow along with Alex’s written tutorial as well. He has even taken it further by using Pi Zero’s USB gadget capabilities to create a tiny Docker Swarm:

Alex Ellis on Twitter

Look ma, no Ethernet! 8 core @Docker 1.12 swarm boom USB OTG @Raspberry_Pi @pimoroni

The Raspberry Pi already makes many computing tasks easier; why not add deploying remote applications to that list with Docker?

31 comments

Avatar

I’m new to cluster computing and had a question someone might be able to help with.

I watched the linked video and understand that using a cluster in this way can distribute tasks out, like at the end of the video he makes 1000 requests and notes how much faster that ran.

My question is, can you pool the resources of the pis and see any gains in performance? For example running a single thread application but having the memory of the other pis available?

Avatar

No, docker does not “cluster” an application in that way. The docker host on each PI would only have access to the memory of that pi.

What Docker would allow you to do is to deploy multiple instances of your application across multiple PI’s. Then, using some load balancer you could then distribute the work across all of them, giving you the performance gain.

Avatar

Towards the end of the video you’ll see the performance gain in scaling up a micro-service from a single Pi to 7. I’m using apache-bench. Happy to answer questions on Twitter or on my blog.

Avatar

Thanks Peter and Alex, I figured that was the case but wanted to check.

Avatar

Actually, it dosen’t even work that way on a single Pi2 or Pi3. A single threaded process will always run on a single core. The advantage comes in when there are more than one thing to do at a time, which happens quite a bit. Very rarely will the memory of a single Pi be insufficient for a single process, so as long as the message passing system between processes is quick enough, it will be like there’s more memory for requests overall, but you have to program for it. The transactions are running on separate Pi’s, so they use the local memory of each Pi when they do so. It’s not quite like what you were asking for, but it’s not so bad overall. This is really cool.

Avatar

Do you use an “network disk” to keep all the containers running on the same content? Or are you duplicating the content across local storage in each Pi?

Avatar

What the video is showing is distributed computing, the easiest analogy is thinking of a Bus containing 60 people doing 50/mph. Adding another lane will allow 60 more people to travel the same distance in that same hour.

The tasks on the raspberry pi won’t be any faster in a cluster, it just results in more tasks being done at the same time.

Avatar

The total execution time is faster when there are more workers able to process the incoming requests. I.e. load-balancing.

Imagine you have 1000 requests being made by 10 users, each of which made 100 requests. The total time to serve all the requests is a lot quicker with 7x quad-core Pis than a single Pi on its own. In my example with Apache Bench you’re effectively increasing your ability to process requests/per second.

In the IoT/Dockercon talk I’m taking advantage of more than 1 Pi not for the added speed/capacity but so we can distribute a set of sensors and monitor a data-warehouse.

Avatar

Hi all,

You guys may want to check out my introduction to Docker on the Pi as a starting point: http://blog.alexellis.io/getting-started-with-docker-on-raspberry-pi/

If you really want to see Docker and Raspberry Pi melded together in harmony then I built a sensor network for Dockercon 2016 with hardware from Pimoroni and it’s all here: http://blog.alexellis.io/dockercon-2016-speaker-notes/

Please get in touch on Twitter – happy to answer questions @alexellisuk

Avatar

Why are you teaching people to execute some random code from the Internet without even using TLS to increase the chances that the code they are executing is vaguely sane?

Avatar

But it uses TLS

Avatar

It does not, the first hit is over HTTP, the redirect to HTTPS happens later:
#v+
$ strace -e connect curl -sSL get.docker.com
connect(3, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr(“52.84.194.65”)}, 16) = -1 EINPROGRESS (Operation now in progress)
connect(4, {sa_family=AF_INET, sin_port=htons(443), sin_addr=inet_addr(“52.84.194.242”)}, 16) = -1 EINPROGRESS (Operation now in progress)
#v-

Avatar

Love the idea of docker on pi! I use docker quite a bit at work (on AWS). Now I get to use it at home on rpi ?

Avatar

Hi, I am a member of linuxserver.io and we’re moving in to making dockers for the armhf platform.

check our repo here:-

https://hub.docker.com/u/lsioarmhf

the dockerfiles source for our images

https://github.com/linuxserver

and our site in general.

https://www.linuxserver.io/

Avatar

kind of silly still using the old “blindly download+execute a shell script as root” routine, on regular debian pc’s docker has an apt repository, does that not include their “official support for raspbian jessie”?

Avatar

Curl|sh is always controversial, Pimoroni also do this for all their packages. Fortunately both Docker and Pimoroni download over HTTPS and from their official websites. Plus there is always the opportunity to read over the script, or not run it.

This is still really early days for ARM support and far better than spending a few hours rebuilding from source.

Maybe you could get involved and help get the Debian Jessie repo updated? Contributions are really welcome.

If anyone is interested, get in touch with the Hypriot guys that helped Docker package this: https://twitter.com/HypriotTweets/

Avatar

But the example above does not use HTTPS for the shell script download. It could be made 10 orders of magnitude better simply by adding “https://” in front of the domain name.

Avatar

As opposed to
1> download the script first.
2> do not go through the script code
3> execute script as root.

What difference does this make?

Avatar

I got docker running nicely on my Pi. But no docker-compose support :( Has anyone had any joy with docker-compose on an RPI?

Avatar

I managed to get docker-machine to connect to the PI and use docker compose.
Checkout the ADDENDUM in this reddit post.

Basically do:
– burn jessie-lite to the SD.

– edit /etc/os-release. Change raspian to debian
PRETTY_NAME=”Raspbian GNU/Linux 8 (jessie)”
NAME=”Raspbian GNU/Linux”
VERSION_ID=”8″
VERSION=”8 (jessie)”
ID=debian <———————————————–
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/&quot;
SUPPORT_URL="http://www.raspbian.org/RaspbianForums&quot;
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs&quot;

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

– go to your base machine and add your keys for passwordless login
$ ssh-copy-id pi@rpi-ds1-000

– add the pi to your machines
docker-machine create \
–driver generic \
–engine-storage-driver=overlay \
–generic-ip-address rpi-ds1-000 \
–generic-ssh-user=pi \
rpi-ds1-000
NOTE: this will end with an error, but it's fine.

– login to the pi and delete folder /etc/systemd/system/docker.service.d/ as it overrides the correct execute code for the daemon.
docker-machine ssh rpi-ds1-000
sudo rm -rf /etc/systemd/system/docker.service.d

– In the Pi, reload systemd daemon and restart docker daemon
sudo systemctl daemon-reload
sudo systemctl restart docker

– check daemon is running
sudo systemctl status docker
● docker.service
Loaded: loaded (/etc/systemd/system/docker.service; enabled)
Active: active (running) since Wed 2016-09-07 23:07:54 UTC; 17h ago
Main PID: 1256 (dockerd)
CGroup: /system.slice/docker.service
├─1256 dockerd -H tcp://0.0.0.0:2376….. <—- this is what you want

– on your base machine check if you can connect
docker-machine ls

ok.. now you can play.

Avatar

This fails for me:

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

It apt-get updates and installs a bunch of stuff, but then craps out with:

“E: Unable to locate package docker-engine”

Nice. Any suggestions?

Avatar

You may need to install the lsb-release package: sudo apt-get install lsb-release

Avatar

Thanx, it worked for me…

Avatar

I’ve just finished the tutorial for the OTG networking portion. Please let me know what you guys think:

Build your PiZero Swarm with OTG networking:

http://blog.alexellis.io/pizero-otg-swarm/

Avatar

Alex,
Thanks Much for this awesome tut. I felt like , i have gained some basics of docker. I will share and recommend this post. Keep them coming.

Avatar

loved the idea of docker! finally i’ll be able to setup discourse at home! Thank you guys!

Avatar

Hi,

I just got Docker 1.12.3 up and running on Raspbian Jessie on my new PicoCluster: http://robferguson.org/2016/11/10/setting-up-my-raspberry-pi-3-picocluster/

Cheers
Rob

Avatar

Fascinating!

Avatar

How do I go the other way? That is, where can I get a raspberry pi image for docker?

Avatar

I’m getting
standard_init_linux.go:178: exec user process caused “exec format error”
when i do docker run hello-world.
this is an undocumented error (searched google, stack overflow, etc). I installed according to curl above; instructions on a clean jessie PRETTY_NAME=”Raspbian GNU/Linux 8 (jessie)”

Leave a Comment

Comments are closed