archive2020

Docker on a Raspberry Pi 4: install, Compose, and the ARM image problem

How to install Docker and docker-compose on Raspbian Buster, and how to check that an image really supports 32-bit ARM before you build a stack on it.

2 min read#ops#docker#raspberry-pi

I am moving my home services (Mosquitto, InfluxDB, Grafana) onto one Raspberry Pi 4 with 4 GB of RAM, in containers. Docker itself installed in one command. The time went into images that do not support ARM.

Install

On Raspbian Buster:

curl -fsSL https://get.docker.com -o get-docker.sh
less get-docker.sh          # read it before you run it
sudo sh get-docker.sh
sudo usermod -aG docker pi  # log out and in again
docker run --rm hello-world

The docker-compose release binaries on GitHub are for x86_64. On a Pi I installed it with pip:

sudo apt install -y python3-pip libffi-dev libssl-dev
sudo pip3 install docker-compose
docker-compose version

This takes a while, because some dependencies compile on the Pi.

Check the image architecture

Raspbian is a 32-bit OS, even on a Pi 4. Docker reports the platform as linux/arm/v7, and an image must have a build for it.

uname -m                      # armv7l
docker info | grep -i arch    # Architecture: armv7l

Before using an image, look at its tags on Docker Hub for arm32v7 or linux/arm/v7. You can also inspect the manifest, with experimental CLI features enabled:

export DOCKER_CLI_EXPERIMENTAL=enabled
docker manifest inspect grafana/grafana:6.7.2 | grep -A2 platform

If there is no ARM build, the container fails at start with:

standard_init_linux.go:211: exec user process caused "exec format error"

The first time I saw this I thought the image was broken. It almost always means the wrong CPU architecture.

Compose file

version: '3.7'
services:
  mosquitto:
    image: eclipse-mosquitto:1.6
    ports:
      - '1883:1883'
    volumes:
      - ./mosquitto/config:/mosquitto/config
      - ./mosquitto/data:/mosquitto/data
    restart: unless-stopped

  influxdb:
    image: influxdb:1.7
    volumes:
      - ./influxdb:/var/lib/influxdb
    environment:
      - INFLUXDB_DB=sensors
    restart: unless-stopped

I pin version tags. latest can change to a release that drops ARM support or changes the config format.

The SD card

Databases write a lot, which wears an SD card and is slow. I put the volumes on a USB SSD, and I limit container logs in /etc/docker/daemon.json:

{
  "log-driver": "json-file",
  "log-opts": { "max-size": "10m", "max-file": "3" }
}
sudo systemctl restart docker

My sensor script that reads I2C stays outside Docker as a plain systemd service. Device access from a container is possible, but I did not see the point for one Python script.