Docker On Raspberry

2/13/2022by admin
  1. Docker On Raspberry
  2. Install Docker On Raspberry Pi 3
  3. Docker On Raspberry Pi
  4. Docker On Raspberry Pi 3
  5. Setup Docker On Raspberry Pi

Raspberry Pi on the other side is a great low cost, credit-card sized computer that plugs into a computer monitor or TV, and uses a standard keyboard and mouse. In this tutorial, I will show you how to install Docker and Docker Compose on Raspberry Pi with just a few easy steps! Installing Docker. I will use the convenience script provided.

Connect with me on Twitter @alexellisuk to go deeper with Docker, DevOps and containers. New Get started with Hands-on Docker on the Raspberry Pi. New Deep-dive video on Docker Swarm on the RPi. 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. What better way to say 'Happy Pi Day' than by installing Docker Engine - Community (CE) 18.09 on Raspberry Pi. This article will walk you through the process of installing Docker Engine 18.09 on a Raspberry Pi. There are many articles out there that show this process, but many failed due to older Engine versions. A Raspberry Pi cluster can be used anytime you want to improve performance or availability, and there are many use cases including serving web content, mining cryptocurrency, processing large amounts of data (using tools like hadoop), and much more. This guide will show you how to run a Raspberry Pi cluster using Docker Swarm.

Jun 24, 2020 On Docker Hub, the number of images for the ARM architecture used by the Raspberry Pi is growing by the day. Even though the majority of images are still only available for the x86 architecture (used by Intel and AMD CPUs, for example), the amount of ARM-compatible images is increasing steadily. 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. Uninstalling Docker on Your Raspberry Pi. Despite having used a convenience script for installation, it's possible to eliminate Docker through the package manager easily: sudo apt-get purge docker-ce. Based on the software version, you’ll require an extra command to eliminate Docker: sudo apt-get purge docker-ce. K3d - makes k3s available on any computer where Docker is also running; KinD - upstream Kubernetes running inside a Docker container. K3s - a light-weight Kubernetes distribution ideal for edge and development - compatible with Raspberry Pi & ARM64 (Equinix Metal, AWS Graviton, etc).

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.

Docker

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.

Docker On Raspberry

  • 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?

Raspberry

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 @[email protected]#ctmtechpic.twitter.com/6o1Ju0u5lm

— comparethemarkt_tech (@comparemkttech) September 21, 2016

5. 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, 2016

The 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?

Raspberry

Running Docker On Raspberry Pi 4

Connect with me on Twitter @alexellisuk to go deeper with Docker, DevOps and containers.

Docker On Raspberry Pi 4 Reddit

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:

Docker On Raspberry Pi 4 Performance

Want to learn the basics of Docker in a hands-on way? Visit or fork my online workshop: Hands-On Docker labs

-->

This is a sample showing how to deploy a Custom Vision model to a Raspberry Pi 3 device running Azure IoT Edge. Custom Vision is an image classifier that is trained in the cloud with your own images. IoT Edge gives you the possibility to run this model next to your cameras, where the video data is being generated. You can thus add meaning to your video streams to detect road traffic conditions, estimate wait lines, find parking spots, etc. while keeping your video footage private, lowering your bandwidth costs and even running offline.

This sample can also be deployed on an x64 machine (aka your PC). It has been ported to the newer IoT Edge GA bits.

Check out this video to see this demo in action and understand how it was built:

Prerequisites

Hardware

You can run this solution on either of the following hardware:

  • Raspberry Pi 3: Set up Azure IoT Edge on a Raspberry Pi 3 (instructions to set up the hardware - use raspbian 9 (stretch) or above) + instructions to install Azure IoT Edge) with a SenseHat and use the arm32v7 tags.

  • Simulated Azure IoT Edge device (such as a PC): Set up Azure IoT Edge (instructions on Windows, instructions on Linux) and use the amd64 tags. A test x64 deployment manifest is already available. To use it, rename the deployment.template.test-amd64 to deployment.template.json, then build the IoT Edge solution from this manifest and deploy it to an x64 device.

Services

Check out the animation below to see how a IoT Edge deployment works. You can also get more details through this tutorial to see how a IoT Edge deployment works. You must have the following services set up to use this sample:

Install Docker On Raspberry Pi 3

  • Azure IoT Hub: This is your Cloud gateway which is needed to manage your IoT Edge devices. All deployments to Edge devices are made through an IoT Hub. You can use the free sku for this sample.
  • Azure Container Registry: This is where you host your containers (e.g. IoT Edge modules). Deployment manifests refer to this container registry for the IoT Edge devices to download their images.You can use the free sku for this sample.

Tooling

You need the following dev tools to do IoT Edge development in general, to make this sample run and edit it:

  • Visual Studio Code: IoT Edge development environment. Download it from here.
  • Visual Studio Code: Azure IoT Edge Extension: An extension that connects to your IoT Hub and lets you manage your IoT Devices and IoT Edge Devices right from VS Code. A must-have for IoT Edge development. Download it from here. Once installed, connect it to your IoT Hub.

To learn more about this development environment, check out this tutorial and this video:

Description of the solution

Modules

Docker On Raspberry Pi

This solution is made of 3 modules:

  • Camera capture - this module captures the video stream from a USB camera, sends the frames for analysis to the custom vision module and shares the output of this analysis to the edgeHub. This module is written in python and uses OpenCV to read the video feed.
  • Custom vision - it is a web service over HTTP running locally that takes in images and classifies them based on a custom model built via the Custom Vision website. This module has been exported from the Custom Vision website and slightly modified to run on a ARM architecture. You can modify it by updating the model.pb and label.txt files to update the model.
  • SenseHat display - this module gets messages from the edgeHub and blinks the raspberry Pi's senseHat according to the tags specified in the inputs messages. This module is written in python and requires a SenseHat to work. The amd64 template does not include this module since it is a raspberry pi only device.

Communication between modules

This is how the above three modules communicate between themselves and with the cloud:

Get started

To deploy the solution on a Raspberry Pi 3

From your mac or PC:

  1. Clone this sample
  2. Update the .env file with the values for your container registry and make sure that your docker engine has access to it
  3. Build the entire solution by right-clicking on the deployment.template.json file and select Build and push IoT Edge Solution (this can take a while...especially to build open-cv, numpy and pillow...)
  4. Deploy the solution to your device by right-clicking on the config/deployment.json file, select Create Deployment for Single device and choose your targeted device
  5. Monitor the messages being sent to the Cloud by right-clicking on your device from the VS Code IoT Edge Extension and select Start Monitoring D2C Message

Note: To stop Device to Cloud (D2C) monitoring, use the Azure IoT Hub: Stop monitoring D2C messages command from the Command Palette (Ctrl+Shift+P).

Docker On Raspberry Pi 3

To deploy the solution on an x64 PC

From your mac or PC:

  1. Clone this sample
  2. Update the .env file with the values for your container registry and make sure that your docker engine has access to it
  3. Build the entire solution by opening the control palette (Ctrl+Shift+P), select Build and push IoT Edge Solution (this can take a while...especially to build numpy and pillow...) and select the deployment.test-amd64.template.json manifest file (it includes a test video file to simulate a camera)
  4. Deploy the solution to your device by right-clicking on the config/deployment.json file, select Create Deployment for Single device and choose your targeted device
  5. Monitor the messages being sent to the Cloud by right-clicking on your device from the VS Code IoT Edge Extension and select Start Monitoring D2C Message

Note: To stop Device to Cloud (D2C) monitoring, use the Azure IoT Hub: Stop monitoring D2C messages command from the Command Palette (Ctrl+Shift+P).

Going further

Update the AI model

Download your own custom vision model from the custom vision service. You just need to replace the ImageClassifierService/app/model.pb and ImageClassifierService/app/labels.txt provided by the export feature of Custom Vision.

Setup Docker On Raspberry Pi

Update the configuration of the camera capture module

Explore the various configuration options of the camera module, to score your ai model against a camera feed vs a video clip, to resize your images, to see logs, etc.

Comments are closed.