The following is a very basic intro to running applications inside Docker containers on a Raspberry Pi, intended for someone who has never used Docker before, but wants to try it out. This was also my first step into Docker on Pi, so I documented it as I went along.
There are a few different tutorials out there for installing Docker on a Raspberry Pi. I found this one works well, and follows the same basic instructions as is recommended for installing Docker on a Linux PC.
These are the commands I ran on the Pi (in case that site disappears):
To start playing with putting your app in a Docker container, first create a file called Dockerfile with the following content:
FROM resin/rpi-raspbian
This simply means we want to create an image that inherits from the resin/rpi-raspbian image, which provides us with a basic Raspbian environment inside a container. (There may be better options out there for base images - this one worked quickly. Curious if others have experience or suggestions around this…)
Then, we’ll build it into a container image called “mycontainer”:
sudo docker build -t mycontainer .
When that’s done, you should see it in the list of images that are available on your system:
sudo docker images
To start up a new container based on that image, run:
sudo docker run --rm -it mycontainer
This puts you directly into a bash shell within the container.
The above is just a very simple way to get started with Docker on a Raspberry Pi.
In most cases, you will want to build out your Dockerfile to include everything necessary to run your app, and set it up to auto-start the container on system boot.
The official documentation for Docker goes into a lot more detail. This page has a good example of how to set up a Flask server inside a Docker container: https://docs.docker.com/get-started/part2/ - which helps to demonstrate how a Dockerfile works and what the whole process of “Dockerizing” an app looks like.