Docker On A Raspberry Pi
- Raspberry Pi 3B+ The Raspberry Pi 3B+ supports USB mass storage boot out of the box. Raspberry Pi 2B v1.2, 3A+, 3B, Compute Module 3, 3+ On the Raspberry Pi 2B v1.2, 3A+, 3B, and Compute Module 3, 3+ you must first enable USB host boot mode. This is to allow USB mass storage boot, and network boot. Note that network boot is not supported on the.
- The Raspberry Pi is a popular single-board computer designed to promote the teaching of computer science in schools. The use of the Raspberry Pi computer ranges from robotics to home automation. Many variations of the Raspberry Pi exist, such as the Raspberry Pi Zero, which is smaller than the more powerful Raspberry Pi 4.
- Turing Pi is a 7 node Raspberry Pi cluster in mini ITX form factor. Run and learn Kubernetes, Dockers, Serverless locally or at the edge.
- Docker pulls the correct image for the current architecture, so Raspberry Pis run the 32-bit Arm version and EC2 A1 instances run 64-bit Arm. The SHA tags identify a fully qualified image variant. You can also run images targeted for a different architecture on Docker Desktop.
The database that is being used in the docker-compose file on the site isn’t compatible with ARM processors, so we’ll need to change that in a bit. But first, we need to get logged in to our Raspberry Pi’s Portainer. This tutorial assumes that you already have Docker and Portainer installed, most likely via OpenMediaVault.
Here are 5 things you need to know about using Docker on the Raspberry Pi from Docker Captain Alex Ellis@alexellisuk
If you're new to Docker then visit my Hands-On Docker online workshop: Hands-On Docker labs
1. Install Docker with one command
Today there is no need to brace yourself for pages of hacks or technical jargon to get Docker onto your device. One command does it all (through apt-get
behind the scenes) - you can even memorise the command:
On Raspbian enter:
Providing you're running Debian or a derivative you're now good to go. The folks at the Docker project build docker/docker from source through CI which includes quality gates around unit and integration tests.

2. Know your Architecture
The Raspberry Pi hardware architecture is called ARM and differs from the architecture behind your regular PC, laptop or cloud instance.
What does that mean? A binary built for either system will not execute on the other.
The helloworld
container will not work on the RPi. I'd suggest starting with my tutorial Get started with Docker on your RPi. It recommends a good set of base images to build what you need - whether that be Go, Node.js, Python, Nginx or something completely different.
The following shortcut will show you the architecture on a Pi or regular Linux machine:
Output from my Raspberry Pi and an Azure cloud instance of Ubuntu
All Pis are compatible with ARMv6 architecture so for simplicity's sake I recommend you build your code through an ARMv6 base image and only pull in official distribution binaries from the likes of Golang, Nodejs, InfluxDB etc where they target that architecture.
What does this mean? It means you can't docker run -d -p 80:80 nginx:latest
- read on for the workaround.
3. You can't trust anyone (yet)
This may seem like a harsh thing to say - but in a climate where even baby monitors and lightbulbs can be taken over to participate in DDOS attacks we need to get smart.
- Don't use an image unless it's official
There are no truly official images but resin/rpi-raspbian
is used by thousands of devices and curated by resin.io. I would recommend creating all your images from this as a base.
The Docker team are working on a set of semi-official images under the namespace armhf and you will see those images coming into play in the Dockerfile.armhf in the docker/docker repo.
Anil from the Docker Inc. team in Cambridge told me how his team are procuring ARM servers like they were going out of fashion in order to create a build-farm to support ARM devices. That infrastructure will enable autobuild support on the public Docker Hub.
- Don't run any binaries you that didn't compile yourself
Even if it takes 2 days to compile PhantomJS - it's still way better than relying on a tar.gz provided by someone you know nothing about on the internet.
Docker Security by Adrian Mouat coins the term poison image for an image tainted with malware.
I have provided a set of Dockerfiles on Github for common software such as Node.js, Python, Consul and Nginx:
Github: alexellis/docker-arm
If you want to create a Docker image for software such as Prometheus.io, Node.js or Golang then head over to their download page and locate the official binary package for ARM - then add it into one of the base images we covered above.
If no binary exists then take the time to re-build from source and don't take any risks. Google the build instructions if you run into issues - they can often be found from a 5-minute search.
4. Get physical
The Raspberry Pi excels at interfacing with hardware through it's 40-pin header. You can talk to just about any electrical component directly or through add-on boards - if it's rated for 3.3v/5v that's a good start. Manufacturers like Pimoroni have a wealth of purpose-built sensor and LED boards which mean no trailing wires or complicated code libraries.
Have you seen my IoT demo from Dockercon and Container.Camp yet?
Pre-recorded demo for Dockercon break glass in case of laptop failure.
All the Dockerfiles, Python code and build instructions are publicly available. I couldn't have done any of this without the Pi's support for physical hardware.
- Container Camp write-up including my IoT demo.
Getting live demonstrations from @alexellisuk at @AgilePBoro@docker#ctmtechpic.twitter.com/6o1Ju0u5lm
— comparethemarkt_tech (@comparemkttech) September 21, 20165. Build a super-computer
Building a cluster has never been easier than with the built-in Swarm Mode from Docker 1.12 onwards. Take it from me because I spent weeks rebuilding the Swarm, Consul binaries etc to set up a 28-CPU swarm for Linux User magazine.
Now I type in one command on my manager and another on the workers. What's more the managers can also do useful work, where as in the original swarm mode that was harder to achieve.
See Docker's presentation from Container.Camp right here - it literally takes two commands to begin building a super-computer.

Want a secure @docker cluster? No problem, it's built-in: two commands and you're set. @containercamppic.twitter.com/viZ3CEy47g
— Alex Ellis (@alexellisuk) September 9, 2016The second most common question I get asked is: can I run a minecraft-super-server with a Pi cluster? The short answer is no and the long answer is yes.
You probably won't be playing a graphics-intensive game at a better FPS rate over your new Pi cluster and it probably won't make loading Chrome any quicker, but it's an invaluable learning tool.
You can can deploy your distributed application at an infrastructure rather than at a specific set of servers. For instance:
- Deploy an application on real hardware
- Simulate network/power failures
- Code against the Docker remote API
- Track down bottle-necks and show scaling different services increases throughput (or not)
Where next?
Connect with me on Twitter @alexellisuk to go deeper with Docker, DevOps and containers.
There's over 28 Raspberry Pi and Docker tutorials on my blog. Explore them all here - ranging from time lapses to IoT sensor monitoring to learning Golang:
Want to learn the basics of Docker in a hands-on way? Visit or fork my online workshop: Hands-On Docker labs
Available on Raspberry Pi 2B v1.2, 3A+, 3B, 3B+, 4B, 400, Compute Module 3, Compute Module 3+ and Compute Module 4 only.
This page explains how to boot your Raspberry Pi from a USB mass storage device such as a flash drive or a USB hard disk. When attaching USB devices, particularly hard disks and SSDs, be mindful of their power requirements. If you wish to attach more than one SSD or hard disk to the Pi, this normally requires external power - either a powered hard disk enclosure, or a powered USB hub. Note that models prior to the Pi 4B have known issues which prevent booting with some USB devices.
Raspberry Pi 4B and Raspberry Pi 400
The Raspberry Pi Pi 400 and newer Raspberry Pi 4B boards support USB boot by default. On earlier Raspberry Pi 4B boards, or to select alternate boot modes, the bootloader must be updated.
Using Raspberry Pi Imager to update the bootloader (recommended)
Raspberry Pi Imager provides a GUI for updating the bootloader
- Download Raspberry Pi Imager
- Select a spare SD card. The contents will get overwritten!
- Launch
Raspberry Pi Imager
- Select
Misc utility images
underOperating System
- Select
Bootloader
- Select
USB
- Select Storage and then Write
Using raspi-config to update the bootloader from within Raspberry Pi OS
To change the boot-mode from within Raspberry Pi OS run raspi-config
- Run
sudo raspi-config
- Select
Advanced Options
- Select
Boot Order
- Select
USB
- Reboot
See also:-
- The bootloader configuration page for other boot configuration options
- The bootloader EEPROM page for more information
Compute Module 4
Please see the Flashing the Compute Module eMMC for bootloader update instructions.
Raspberry Pi 3B+
The Raspberry Pi 3B+ supports USB mass storage boot out of the box.
Raspberry Pi 2B v1.2, 3A+, 3B, Compute Module 3, 3+
On the Raspberry Pi 2B v1.2, 3A+, 3B, and Compute Module 3, 3+ you must first enable USB host boot mode. This is to allow USB mass storage boot, and network boot. Note that network boot is not supported on the Raspberry Pi 3A+.
To enable USB host boot mode, the Raspberry Pi needs to be booted from an SD card with a special option to set the USB host boot mode bit in the one-time programmable (OTP) memory. Once this bit has been set, the SD card is no longer required. Note that any change you make to the OTP is permanent and cannot be undone.
On the Raspberry Pi 3A+, setting the OTP bit to enable USB host boot mode will permanently prevent that Pi from booting in USB device mode.
You can use any SD card running Raspberry Pi OS to program the OTP bit.
Enable USB host boot mode with this code:
This adds program_usb_boot_mode=1
to the end of /boot/config.txt
.
Note that although the option is named program_usb_boot_mode
, it only enables USB host boot mode. USB device boot mode is only available on certain models of Raspberry Pi - see USB device boot mode.
The next step is to reboot the Raspberry Pi with sudo reboot
and check that the OTP has been programmed with:
Docker On A Raspberry Pi Emulator
Check that the output 0x3020000a
is shown. If it is not, then the OTP bit has not been successfully programmed. In this case, go through the programming procedure again. If the bit is still not set, this may indicate a fault in the Pi hardware itself.
If you wish, you can remove the program_usb_boot_mode
line from config.txt
, so that if you put the SD card into another Raspberry Pi, it won't program USB host boot mode. Make sure there is no blank line at the end of config.txt
.
You can now boot from a USB mass storage device in the same way as booting from an SD card - see the following section for further information.
Booting from the USB mass storage device
The procedure is the same as for SD cards - simply image the USB storage device with the operating system image.
After preparing the storage device, connect the drive to the Raspberry Pi and power up the Pi, being aware of the extra USB power requirements of the external drive.After five to ten seconds, the Raspberry Pi should begin booting and show the rainbow splash screen on an attached display. Make sure that you do not have an SD card inserted in the Pi, since if you do, it will boot from that first.
See the bootmodes documentation for the boot sequence and alternative boot modes (network, USB device, GPIO or SD boot).
Known issues (not Pi 4B, CM4 and Pi 400)
- The default timeout for checking bootable USB devices is 2 seconds. Some flash drives and hard disks power up too slowly. It is possible to extend this timeout to five seconds (add a new file
timeout
to the SD card), but note that some devices take even longer to respond. - Some flash drives have a very specific protocol requirement that is not handled by the bootcode and may thus be incompatible.
Special bootcode.bin-only boot mode (not Pi 4B, CM4 and Pi 400)
Docker On A Raspberry Pi Configuration
If you are unable to use a particular USB device to boot your Raspberry Pi, an alternative for the Pi 2B v1.2, 3A+, 3B and 3B+ is to use the special bootcode.bin-only boot mode as described here. The Pi will still boot from the SD card, but bootcode.bin
is the only file read from it.
