Installing Docker On RaspberryPi

The RaspberryPi is an arm-based computer. As such, installation of software must target the specific architecture. In order to install the software needed to run docker containers, a few steps are available. The installation consists of 2 major components:

  • The Docker sub-system.
  • The docker-compose framework, a python-based yaml scripting framework that makes it easier to create docker containers.

NOTE:

This guide assumes a clean RaspberryPi Raspbian installation.

Docker is used to run software packages called “containers”. Containers are isolated from each other and bundle their own tools, libraries and configuration files; they can communicate with each other through well-defined channels. All containers are run by a single operating system kernel and are thus more lightweight than virtual machines. Containers are created from “images” that specify their precise contents. Images are often created by combining and modifying standard images downloaded from public repositories.

The beauty of docker is that the containers can be moved anywhere there is a docker server, and the software that the containers run will run exactly as it was running on the previous server. There is no other configuration requirement other than having a docker installation that matches the previous processor architecture. This makes rebuilding servers a breeze.

Assuming you are using Raspbian jessie or newer (8+), install the pre-requisites as follows. It is easier to execute all of the commands when elevating to root once, by executing sudo su.

apt-get update
apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common vim

Add docker's official GPG key by executing

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

Use the following command to set up the stable repository, and update the repository afterwards.

echo "deb [arch=armhf] https://download.docker.com/linux/debian $(lsb_release -cs) stable">/etc/apt/sources.list.d/docker-ce.list
apt-get update

Install the latest version of docker-ce as follows:

apt-get install docker-ce

Eventhough you are ready to run docker containers with just having docker, it is far easier to get used to handling docker containers with docker-compose. Compose is a python-based tool for defining and running multi-container Docker applications. Install it by executing:

apt-get install python-pip
pip install docker-compose

Docker is by defult ran by user root. My personal preference for setting up the environment is to divide the setup into 2 parts:

  • docker-compose: The folder where all the compose definitions are located. Consists of pure docker-compose.yml definitions.
  • docker-persist: The folder where all the user data generated by the running containers is stored.

Create the two folders in the home of user root as follows:

cd ~
mkdir docker-compose
mkdir docker-persist

While managing docker containers is best done from the command line as the user root, there is benefit in installing a web-based UI called portainer which allows you to manage your containers in a more visual way. In order to install this:

cd ~/docker-compose
mkdir portainer
vim docker-compose.yml
This will create a compose file inside the portainer folder. After this, while in the vim interface, press INSERT or the letter 'i' to enter insert mode, and paste the following compose definition. In YAML syntax the spaces matter.
version: '3.2'
services:
  portainer:
    image: portainer/portainer:arm
    restart: always
    container_name: portainer
    ports:
      - '9000:9000'
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /root/docker-persist/portainer/data:/data
Save the file by pressing ESC and then typing :x and pressing ENTER. After saving, start the container by executing:
docker-compose up -d
The command will start the management interface as a permanent serviceon port 9000. You will be able to access it by opening a browser and going to http://localhost:9000 (if on the raspberry pi), or http://raspberrypi:9000 if connecting from another machine in the network.

You will be prompted to enter password for the administrative user. Enter a password of your choice.

After that, you will be logged in, and will be able to see the running containers, volumes and images, with the ability to stop start, destroy objects as needed. Again, portainer is just a visual tool. You can do more advanced management by using the terminal.

With this, you will have a functional docker environment on your RaspberryPi.

  • linux/installing_docker_on_raspberrypi.txt
  • Last modified: 2018/10/26 18:35
  • by bkraul