Single board computer projects

Using Docker

last updated: 2022-02-21

Quick links


Everybody is talking of Docker. As a new OpenHAB version (3) is out, and I have to update my home server. Docker should allow a painless migration because both systems (v2, v3) can run simultaneously. Here I try to document the important steps to get everything running.

A good starting point are the pages and for openHAB

Install Docker

Install Docker engine on Debian (bullseye)

Infos can be found here:

On my udoo server (x86_64) I'm running Debian 11 (bullseye). First we install the following packages if they are missing:

    sudo apt update
    sudo apt upgrade
    sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release

Add GPG key and add the stable repo to your sources.list:

    curl -fsSL | sudo gpg --dearmor -o \
    echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \ \ $(lsb_release -cs) stable" | sudo tee \
    /etc/apt/sources.list.d/docker.list > /dev/null

Now we install the Docker engine:

    sudo apt-get update
    sudo apt-get install docker-ce docker-ce-cli

Test if everything is ok:

    sudo docker run hello-world

On Debian (Ubuntu), the Docker service starts on boot by default.

Install Docker engine on Raspi OS

For the Raspberry Pi, installing using the repository is not yet supported (2022-02). But we get a convenience script :).

    sudo apt update
    sudo apt upgrade
    sudo curl -sSl | sh
    sudo docker run hello-world

On Debian (raspios, Ubuntu), the Docker service starts on boot by default. If it does not on Raspi we can use systemctl with enable. Other possibilities for systemctl are status, stop and start (restart):

    sudo systemctl enable docker
    sudo systemctl status docker

Docker as a non-root user

If we want to run a container without sudo we get an error. This is because docker group is created but no users are added to it. So we need to use sudo or better we engage optional procedures for configuring Linux hosts to work better with Docker. These steps are explained here:

    sudo groupadd docker
    sudo usermod -aG docker $USER
    newgrp docker
    docker run hello-world

Docker commands

All docker commands must be used with sudo if we didn't add a user to the docker group!

List version:

    docker version

View container (and get names created by docker):

    docker ps -a

View images:

    docker images

Get a newer image (update e.g. ubuntu image):

    docker image pull ubuntu

Run a container (-i interactive, -t pseudo-terminal, --name name, -h host-name). We can specify a version with a colon. Best to give an own name for the container.

    docker run -it ubuntu`
    docker run -it ubuntu:18.10`
    docker run -it --name myubuntu -h ubuhost ubuntu:18.10`

With run there is always a new container, so use docker start with your container name to run the same container (without -t)!

    docker start -i myubuntu`

With exec start a second process (second terminal to run e.g. a command) of the same container. We can stop it with Q:

    docker exec -it myubuntu /usr/bin/top

Install Docker-compose

As we need more container (openHAB, influxDB, Grafana) we will use Docker-compose to call our containers. Docker-compose uses a YAML text file to run the different container. More infos:

Install on Debian

Only on Linux we need to install Docker-compose ( The current version is 1.29.2. For another version, change the command!

    sudo curl -L " \
    docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    sudo chmod +x /usr/local/bin/docker-compose

Install on Raspi:

For the Raspberry Pi we use pip:

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

Test the installation.

    docker-compose --version

Docker YAML files

Now let's have a look at the following YAML file from

    # save as docker-compose.yml or openhab.yml
    version: '3.8'

        image: "openhab/openhab:3.2.0" # stable 2022-02
        container_name: openhab
        restart: always
        network_mode: host
          - "/etc/localtime:/etc/localtime:ro"
          - "/etc/timezone:/etc/timezone:ro"
          - "./openhab/openhab_addons:/openhab/addons"
          - "./openhab/openhab_conf:/openhab/conf"
          - "./openhab/openhab_userdata:/openhab/userdata"          
          OPENHAB_HTTP_PORT: "9080"
          OPENHAB_HTTPS_PORT: "9443"
          EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Luxembourg"

We use the network of the host, because openHAB requires UPnP discovery. Unfortunately port mapping is incompatible with this network_mode. Because I use 2 versions of openHAB, I change the ports from 8xxx to 9xxx. The openHAB directories are created from docker-compose.

We save the file as text-only with the name openhab.yml and start it with the up command:

    docker-compose -f openhab.yml up --remove-orphans -d

Without -f and the filename docker-compose searches for a file named docker-compose.yml in the current directory. The option -d stands for detached mode, meaning the container is running in the background (default = foreground).

To stop or (re)start the running container we use:

    docker-compose -f openhab.yml stop
    docker-compose -f openhab.yml start

Interesting links