Cannot set host name in container


Am trying to set a custom hostname in a container running on a device with balena OS.
Would like to use the device variable as part of the hostname.
In Windows Desktop I can set the option hostname in the docker-compose.yml file, like:
hostname: app-a.${
But in balena, this does not work. I tried to use the device variable as well as the custom configuration option for the device with no success.
The device variable HOSTNAME is set within a container as an environment variable,but not substituted by the docker engine.
Attempting to set the hostname at container start seems would not help, because when I try to set it in the terminal within a container, getting a permission denied error.
This is a significant problem in a container running OPC UA Server because it returns the hostname as part of the endpoint, which is later used by the client to connect to it. If the hostname cannot be resolved correctly, some clients cannot connect to the server then.

Hello @Ravil what are you using to set a custom hostname in a container?

Could you please share how do you define your containers in the docker-compose?

Here is the piece in docker-compose.yml:

# Demo OPC UA Server
    image: ''
    hostname: opcplc.${HOST_HOST_NAME:-local}
      - '50000:50000'
    command: '--autoaccept'
      - obox
      - 'opcplc-data:/app/pki'  

This is the console output from this container.
The device variable is defined but is not substituted.
If I run docker-compose config in the development machine, (Windows), it does substitute properly, so yml file format is correct I believe. It does not even use the default value.