SMB network access problems on the volumes of openHAB docker

Dear community members,

my openHab 4.1.1 runs in a docker environment on an Openmediavault 6 server (OMV6). From time to time I update my items and things files over the Windows SMB share. For this purpose I have exported the docker volumes of the openHAB container and made them abailable via windows SMB on the network. Sometimes I get access problems on the openHAB files and I tracked it down to the specific user/group which is used when starting the docker container.

My setup:
On my OMV setup I have a specific user for docker with name docker1 (ID: 1002) and membership in group users (ID: 100). In OMV6 a dockercompose file is used to handle the container. It looks like:

services:
  openhab:
    image: "openhab/openhab:4.1.1"
    restart: always
    network_mode: host
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/etc/timezone:/etc/timezone:ro"
     
      # config in SMB folders
      - "/srv/dev-disk-by-uuid-9e2c512c-33d2-4a6a-aa1b-e10a5f6eea6a/openhab_addons:/openhab/addons"
      - "/srv/dev-disk-by-uuid-9e2c512c-33d2-4a6a-aa1b-e10a5f6eea6a/openhab_conf:/openhab/conf"
      - "/srv/dev-disk-by-uuid-9e2c512c-33d2-4a6a-aa1b-e10a5f6eea6a/openhab_userdata:/openhab/userdata"
    environment:
      CRYPTO_POLICY: "unlimited"
      EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Berlin"
      OPENHAB_HTTP_PORT: "8180"
      OPENHAB_HTTPS_PORT: "8543"
      PUID: 1002 
      PGID: 100 

The folders outside the container usually have the following permissions:
drwxrwsr-x 2 root users 4096 25. Feb 11:25 openhab_addons
drwxrwsr-x 14 root users 4096 23. Feb 17:20 openhab_conf
drwxrwsr-x 12 root users 4096 24. Feb 18:18 openhab_userdata

With ps aux | grep openhab I can see, that the docker is started with the user openhab (ID: 9001), which is usually the standard openhab user in an openhab group (ID: 9001):

9001 2768061 1.2 4.5 8012960 722312 ? Sl Feb24 13:02 /usr/lib/jvm/java-17-openjdk-amd64/bin/java …

This is causing from time to time a change of the owner / group of the container volumes to
drwxrwsr-x 3 9001 9001 4096 23. Feb 17:56 openhab_addons
drwxrwsr-x 14 9001 9001 4096 23. Feb 17:20 openhab_conf
drwxrwsr-x 12 9001 9001 4096 24. Feb 18:18 openhab_userdata

This is very annoying because I cannot access these volumes over windows SMB anymore with my users which are in the users group of OMV. If I change back the owner / group to root / users and do a chmod 775, everything will work fine again.

As you can see from above, I am trying to force openHab in the dockercompose file to start with user docker1 (ID: 1002) and group users (ID: 100). But obviously the container is started with user 9001.

What do I need to do to start the openHAB with my docker1 user?
Will this solve the windows SMB access problem?

According to the docs the environment variables that control the user and group OH runs under are USER_ID and GROUP_ID.

:person_shrugging: If it works for files that have the correct ownership now, I imagine it will continue to work once you correctly get OH to run as the user and group you want.

Thank you for this hint. I put in the dockercompose file:

    environment:
      CRYPTO_POLICY: "unlimited"
      EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Berlin"
      OPENHAB_HTTP_PORT: "8180"
      OPENHAB_HTTPS_PORT: "8543"
      USER_ID: 1002
      GROUP_ID: 100

And ps aux is showing, that openHAB started with the docker1 user:
docker1 2884725 263 3.6 8034820 587596 ? Sl 18:52 1:05 /usr/lib/jvm/java-17-openjdk-amd64/bin/java

The folders have the following permissions:
drwxrwsr-x 2 docker1 users 4096 25. Feb 11:25 openhab_addons
drwxrwsr-x 14 docker1 users 4096 23. Feb 17:20 openhab_conf
drwxrwsr-x 12 docker1 users 4096 24. Feb 18:18 openhab_userdata

And the SMB access with users from the users group also works now!

Great, thank you!

By the way: I also learnt that there are several ways to set the environmental variable (Link). The composefile definitely is a good choice. Put OMV also offers to create a separate .env file.