Running openHAB in Docker


I’ve been running openHAB for some time and I recently decided to recreate my setup in docker to run it on a bigger shared server instead of a Raspberry Pi 4. It was fairly easy but I did have to deviate a little for my configuration from what the documentation suggested.

I like using docker-compose to launch my containers and for my setup I rely on MQTT heavily for some things I do so I made sure both are configured. I also use Traefik to expose some services and therefor I had to change some ports around a bit.

The host server runs in Arch Linux and caused a few issues that I’ll get into shortly.

Docker Compose

version: '3.7'

    image: openhab/openhab:latest
      - 9085:9085
      - mqtt
      - ./conf:/openhab/conf
      - ./userdata:/openhab/userdata
      - ./addons:/openhab/addons
      - ./cont-init.d:/etc/cont-init.d
      - OPENHAB_HTTP_PORT=9085
      - CRYPTO_POLICY=unlimited
      - USER_ID=1000
      - GROUP_ID=1000
      - "/dev/ttyUSB0:/dev/ttyUSB0"
      - "/dev/ttyUSB1:/dev/ttyUSB1"
#      - "/dev/ttyACM0:/dev/ttyACM0"
    - "traefik.enable=true"

    - "traefik.http.routers.openhab-s.middlewares=https_redirect@file"
    - "traefik.http.routers.openhab-s.rule=Host(``)"
    - "traefik.http.routers.openhab-s.entrypoints=web"

    # https
    - "traefik.http.routers.openhab.rule=Host(``)"
    - "traefik.http.routers.openhab.entrypoints=websecure"
    - "traefik.http.routers.openhab.tls=true"
    - "traefik.http.routers.openhab.tls.certresolver=myresolver"
    - "traefik.http.routers.openhab.service=openhab"
    - ""

    image: eclipse-mosquitto:latest
      - ./mqtt/config:/mosquitto/config
      - ./mqtt/data:/mosquitto/data
      - ./mqtt/log:/mosquitto/log
    user: "1000:1000"
      - 1883:2883


Most of the contents of the docker-compose.yml file are for openHAB and a few are for MQTT so I’ll mostly document those for openHAB.



I created a conf folder to hold the following folders: automation, html, icons, items, persistence, rules, scripts, services, sitemaps, sounds, things and transform. This is the main place I’d add/edit files to run my home.


This folder will get automatically created when I run docker-compose but it will contains openHAB state data and logs, etc. I frequently monitor logs with tail:

tail -F ./userdata/logs/*.log


I dont use this for anything yet.


This folder contains a few extra scripts that I run during openHAB startup. For my setup, I found ArchLinux doesn’t have the timezone/localtime files configured the way the documentation suggests so my script maps things so they work better at startup.

echo "setting timezone"
rm -f /etc/localtime
rm -f /etc/timezone
ln -s /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
echo "America/Los_Angeles" > /etc/timezone

Arch linux also maps the uucp group to a different ID than what the openHAB container uses so I modified it to fix issues I had with permissions at startup:

sed -e 's/uucp:x:10/uucp:x:987/' /etc/group -i


I have a user on the host system in the uucp group to access the Z-Wave / ZigBee dongle and I want all the files created by the container to be own by the same UID so I added the USER_ID and GROUP_ID values.


My dongle wasn’t mapped to ttyACM0 on my system so I just made sure to mount the correct ones.


These labels are only used for Traefik. If you don’t use it then you won’t need them.


The only interesting thing about the MQTT setup is the ports. Initially I tried running everything in the normal port 1883 but I ran into permission problems. Someone online suggested using 8883 but that seemed to cause protocol problems (TLS port) so I ended up using 2883 but I didn’t want to reconfigure everything to use a different port. This resulted in a single file:

persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log

allow_anonymous true
listener 2883

protocol mqtt