Problems with docker-compose

I am trying to move my openHAB installation from Openhabian to a docker based solution on RPI3B.

I have created all the containers that I need for now and started them with “docker run”. All seems to work OK. Now I am trying to build a docker-compose file and I cannot get it to work. Here is the “docker run” command that does work (I have created a bridged network (“openhabnet”) to which I connect all the containers for home automation):

docker run -it\
        --name openhab \
        --network openhabnet \
        --network-alias openhab \
        -p 192.168.64.20:8080:8080 \
        -p 192.168.64.20:8443:8443 \
        -p 192.168.64.20:8101:8101 \
        -v /etc/localtime:/etc/localtime:ro \
        -v /etc/timezone:/etc/timezone:ro \
        -v /home/pi/docker/openhab/conf:/openhab/conf \
        -v /home/pi/docker/openhab/userdata:/openhab/userdata \
        -v /home/pi/docker/openhab/addons:/openhab/addons\
        -d \
        -e USER_ID=999 \
        -e GROUP_ID=995 \
        --restart=always \
        openhab/openhab:latest

I created then the following docker-compose.yml

version: '3.7'

services:
  openhab:
    image: "openhab/openhab:latest"
    container_name: "openhab"
    user: "${UID}:${GID}"
    restart: always
    networks:
      openhabnet:
        aliases:
          - openhab
    ports: 
      - "192.168.64.20:8080:8080"
      - "192.168.64.20:8443:8443"
      - "192.168.64.20:8101:8101"
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/etc/timezone:/etc/timezone:ro"
      - "/home/pi/docker/openhab/conf:/openhab/conf"
      - "/home/pi/docker/openhab/userdata:/openhab/userdata"
      - "/home/pi/docker/openhab/addons:/openhab/addons"
    environment:
      OPENHAB_HTTP_PORT: "8080"
      OPENHAB_HTTPS_PORT: "8443"
      EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Helsinki"
      USER_ID: "999"
      GROUP_ID: "995"

networks:
  openhabnet:
    driver: bridge
    ipam:
      config:
      - subnet: 172.19.0.0/24

Starting this with “docker-compose up” results in this error message if I do not manually remove the cache and tmp directories:

openhab    | ++ test -t 0
openhab    | ++ echo false
openhab    | + interactive=false
openhab    | + set -euo pipefail
openhab    | + IFS='
openhab    |    '
openhab    | + '[' limited = unlimited ']'
openhab    | + rm -f /openhab/runtime/instances/instance.properties
openhab    | + rm -f /openhab/userdata/tmp/instances/instance.properties
openhab    | rm: cannot remove '/openhab/userdata/tmp/instances/instance.properties': Permission denied

If I do not remove the directory first manually (using rm -rf ) the this error message occurs:

Attaching to openhab
openhab    | ++ test -t 0
openhab    | ++ echo false
openhab    | + interactive=false
openhab    | + set -euo pipefail
openhab    | + IFS='
openhab    |    '
openhab    | + '[' limited = unlimited ']'
openhab    | + rm -f /openhab/runtime/instances/instance.properties
openhab    | + rm -f /openhab/userdata/tmp/instances/instance.properties
openhab    | rm: cannot remove '/openhab/userdata/tmp/instances/instance.properties': Permission denied

I do not understand why this happens. The user-id and group-id do exist on the docker-host. It seems to be related to the access rights but cannot figure it out.

Any help is welcome.

Does it work if you remove user: "${UID}:${GID}" from the compose file?

IIRC the entrypoint script first updates files using elevated permissions and then starts the process using the USER_ID / GROUP_ID specified.

Thanks a lot. Sometimes one is just blind when reveiwing own work.

This was spot on: when I removed user: "${UID}:${GID}" from the docker-compose file it started work.

This line got introduced because I tried to start openHAB and Mosquitto together and I added this line to the wrong section. And for some reason I overlooked it all the time after I removed the Mosquitto part for trouble shooting :frowning:

Now all seems to work. For Mosquitto I am providing user ID and group ID via variables and decided to do this also for the openhab user environment variables.

I start now docker-compose with this line (put in a script):

CURRENT_UID=$(id -u):$(id -g) OH_UID=$(id -u openhab) OH_GID=$(id -g openhab) docker-compose up

The docker-compose file that works looks like this:

version: '3.7'

services:
  openhab:
    image: "openhab/openhab:latest"
    container_name: "openhab"
    restart: always
    networks:
      openhabnet:
        aliases:
          - openhab
    ports: 
      - "192.168.64.20:8080:8080"
      - "192.168.64.20:8443:8443"
      - "192.168.64.20:8101:8101"
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/etc/timezone:/etc/timezone:ro"
      - "/home/pi/docker/openhab/conf:/openhab/conf"
      - "/home/pi/docker/openhab/userdata:/openhab/userdata"
      - "/home/pi/docker/openhab/addons:/openhab/addons"
    environment:
      OPENHAB_HTTP_PORT: "8080"
      OPENHAB_HTTPS_PORT: "8443"
      EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Helsinki"
      USER_ID: "${OH_UID}"
      GROUP_ID: "${OH_GID}" 

  mosquitto:
    image: "eclipse-mosquitto:latest"
    container_name: "mosquitto"
    user: "${CURRENT_UID}"
    restart: always
    networks:
      openhabnet:
        aliases:
          - mosquitto
    ports:
      - 192.168.99.20:1883:1883
      - 192.168.99.20:9001:9001
    volumes:
      - "/home/pi/docker/mosquitto/config:/mosquitto/config"
      - "/home/pi/docker/mosquitto/log:/mosquitto/log"
      - "/home/pi/docker/mosquitto/data:/mosquitto/data"
    environment:
        - TZ=Europe/Helsinki

networks:
  openhabnet:
    driver: bridge
    ipam:
      config:
      - subnet: 172.19.0.0/24

Note: I have different networks for devices and the users so I am exposing the services only to some IP addresses.

1 Like

Nice that it works now! I also have a secondary OH instance running on a RPi3B with Docker. Some think Docker is too heavy for a RPi3B but I think they’ve never tried it. :slight_smile:

I can recommend hypriot as a distro for the rPi. It comes with docker installed. Runs like a charm.

1 Like

Thanks for the hint. I just read about hypriot. I am considering to install a second zigbee2mqtt gateway. This would be perfect for testing hypriot.

I started with RPi3B (booting from SSD) to get to know docker and try it out. Today I got my docker-compose file working that starts:

  • openHAB
  • Mosquitto
  • InfluxDB
  • Grafana
  • Node-RED
  • zigbee2mqtt
  • zigbee2mqtt Assistant
    (unfortunately I cannot get the tellstick to mqtt to work)

There is almost nothing configured yet. Just some items to verify that the system works. I will start moving things over one-by-one when I have some time and will check the load then. I just had a look using top and the RPi is mostly idling with less than 10% CPU load. At some point it was peaking at 25%. If the performance becomes a problem I will move to a RPi4 or put it on my NAS that I still need to reinstall. The RPi3B was available for playing around with and is working really well so far. I am quite impressed by the it.

Do you share your docker compose file?

Sure I can share. Please note the following:

  • all containers areconnected to the customer bridge “openhabnet”
  • I am using aliases to connect the machines to each other
  • the RPi has several IP addresses and I expose different ports to different IP addresses (e.g. I have one network for my sensors so Mosquitto is connected to that one). This can, of course, easily be changed.
  • ports needed only within the openhabnet are not exposed (e.g. influxdb)

I just got it to work and it seems to work. But it is not thoroughly tested. I hope this helps someone. It took me quite a while to figure it all out (for example on how to handle the different IP addresses which are on different VLANs on the single Ethernet interface (the network config is not shown here though) and to map the containers to it).

Startup command:

CURRENT_UID=$(id -u) CURRENT_GID=$(id -g) OH_UID=$(id -u openhab) OH_GID=$(id -g openhab) docker-compose up -d

docker-compose.yml

version: '3.7'

services:
  openhab:
    image: "openhab/openhab:milestone"
    container_name: "openhab"
    restart: always
    networks:
      openhabnet:
        aliases:
          - openhab
    ports: 
      - "192.168.64.20:8080:8080"
      - "192.168.64.20:8443:8443"
      - "192.168.64.20:8101:8101"
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/etc/timezone:/etc/timezone:ro"
      - "/home/pi/docker/openhab/conf:/openhab/conf"
      - "/home/pi/docker/openhab/userdata:/openhab/userdata"
      - "/home/pi/docker/openhab/addons:/openhab/addons"
    environment:
      OPENHAB_HTTP_PORT: "8080"
      OPENHAB_HTTPS_PORT: "8443"
      EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Helsinki"
      USER_ID: "${OH_UID}"
      GROUP_ID: "${OH_GID}" 

  mosquitto:
    image: "eclipse-mosquitto:latest"
    container_name: "mosquitto"
    user: "${CURRENT_UID}:${CURRENT_GID}"
    restart: always
    networks:
      openhabnet:
        aliases:
          - mosquitto
    ports:
      - 192.168.99.20:1883:1883
      - 192.168.99.20:9001:9001
    volumes:
      - "/home/pi/docker/mosquitto/config:/mosquitto/config"
      - "/home/pi/docker/mosquitto/log:/mosquitto/log"
      - "/home/pi/docker/mosquitto/data:/mosquitto/data"
    environment:
        - TZ=Europe/Helsinki

  nodered:
    depends_on:
      - openhab
    image: "nodered/node-red-docker:0.20.7-rpi"
    container_name: "nodered"
    restart: always
    networks:
      openhabnet:
        aliases:
          - nodered
    ports: 
      - "192.168.67.20:1880:1880"
    volumes:
      - "/home/pi/docker/nodered:/data"
  
  influxdb:
    image: "influxdb"
    container_name: "influxdb"
    restart: always
    networks:
      openhabnet:
        aliases:
          - influxdb
    volumes:
      - "/etc/timezone:/etc/timezone:ro"
      - "/etc/localtime:/etc/localtime:ro"
      - "/home/pi/docker/influxdb:/var/lib/influxdb"

  grafana:
    depends_on: 
      - influxdb
    image: "grafana/grafana:master"
    container_name: "grafana"
    restart: always
    networks:
      openhabnet:
        aliases:
          - grafana
    ports:
      - "192:168.64.20:3000:3000"
    volumes:
      - "/home/pi/docker/grafana:/var/lib/grafana"
  
  zigbee2mqtt:
    depends_on:
      - mosquitto
    image: "koenkk/zigbee2mqtt:arm32v6"
    container_name: "zigbee2mqtt"
    restart: always
    networks:
      openhabnet:
        aliases:
          - zigbee2mqtt
    volumes:
      - "/home/pi/docker/zigbee2mqtt//data:/app/data"
      - "/run/udev:/run/udev:ro"
    devices: 
      - "/dev/ttyACM0:/dev/ttyACM0"
    environment:
      - TZ=Europe/Helsinki
  
  zigbee2mqttGUI:
    depends_on:
      - zigbee2mqtt
    image: "carldebilly/zigbee2mqttassistant"
    container_name: "zigbee2mqttGUI"
    restart: always
    networks:
      openhabnet:
        aliases:
          - zigbee2mqttGUI
    ports:
      - 192.168.67.20:8880:80
    environment:
      - Z2MA_SETTINGS__MQTTSERVER=mosquitto
      - Z2MA_SETTINGS__MQTTUSERNAME=MQTT_user 
      - Z2MA_SETTINGS__MQTTPASSWORD=xxxxx

networks:
  openhabnet:
    driver: bridge
    ipam:
      config:
      - subnet: 172.19.0.0/24
1 Like

I tested today moving my installation to another RPi3 (installing a fresh Raspbian and transfer my backup) and got an error when executing docker-compose. I needed to change the line

image: "koenkk/zigbee2mqtt:arm32v6"

to

image: "koenkk/zigbee2mqtt:latest"

Then it worked fine. There seem to have been some recent changes.

Hi there, has anyone managed to connect a remote zigbee2mqtt gateway based on ESP8266?
If yes, how did you adapt the below configuration line

    devices: 
      - "/dev/ttyACM0:/dev/ttyACM0"

from a physical device format:

/dev/ttyACM0

to a tcp based device:

tcp://192.168.2.13:20108

?

There is an alternate docker image available, with integrated socat support, but I am actually not using socat in my setup.

Thanks

Problem solved

I declared the serial option in configuration.yaml.
I also had to change the serial device from /dev/ttyACM0 to /dev/ttyAMA0 on the physical (left) side of the equation:

docker-compose.yml:

   devices: 
       - "/dev/ttyAMA0:/dev/ttyACM0"

configuration.yaml:

serial:
  port: 'tcp://10.0.0.96:61775'