Openhab Docker port reconfiguration

  • Platform information:
    • Hardware: CPUArchitecture/RAM/storage
    • OS: what OS is used and which version
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version:
  • Issue of the topic: please be detailed explaining your issue
  • Please post configurations (if applicable):
    • Items configuration related to the issue
    • Sitemap configuration related to the issue
    • Rules code related to the issue
    • Services configuration related to the issue
  • If logs where generated please post these here using code fences:

I installed OpenHAB as Docker container on my Raspberry PI.
I’m also running different applications on this host so, I have the problem that most people do have in that case: my port 8080 and 8443 are already in use.

I searched the forum already for the solution and found different threads advising me to change the ports in the environment variables for spawning the container.
Therefore I edited my command like that:

docker run \
         --name openhab \
         --net=host \
         -v /etc/localtime:/etc/localtime:ro \
         -v /etc/timezone:/etc/timezone:ro \
         -v /opt/openhab/conf:/openhab/conf \
         -v /opt/openhab/userdata:/openhab/userdata \
         -v /opt/openhab/addons:/openhab/addons \
         -d \
         -e USER_ID=1001 \
         -e GROUP_ID=9001 \
         -e OPENHAB_HTTP_PORT=8081 \
         -e OPENHAB_HTTPS_PORT=8444 \
         --restart=always \
         openhab/openhab:2.5.8

With this command, my port is still listening on 8080/8443 so i’ll be redirected to my other application.

Also tried this one:
docker run
–name openhab
–net=host
-v /etc/localtime:/etc/localtime:ro
-v /etc/timezone:/etc/timezone:ro
-v /opt/openhab/conf:/openhab/conf
-v /opt/openhab/userdata:/openhab/userdata
-v /opt/openhab/addons:/openhab/addons
-d
-e USER_ID=1001
-e GROUP_ID=9001
-p 8080:8081
-p 8433:8434
–restart=always
openhab/openhab:2.5.8

It’s also not working.
Any help on that?

This statement doesn’t make sense. Of course port 8080/8443 is still being listened to and of course opening the webpages served on that port opens the other application. You’ve not changed the other application to listen on the other port.

If the environment variables did work, you would access openHAB on port 8081/8444 now. If those variables did not work, you will see an error when the docker container starts up (use the docker logs capability or grep the syslogs for that container ID) and you will see a bind exception indicating that openHAB is unable to bind to port 8080.

The -p options have no effect when you use --net=host.

Hey don’t have any error in the logs - so it should work right?

When i try to access the site again with port 8081 or 8434 it’s giving me “page not found”

This is your answer.

Why are you using --net=host? Use bridge mode, keep the original ports on the openhab container and just bind them to different ports like you did in your second example except you have them around the wrong way I think. It’s host:container:

-p 8081:8080
-p 8444:8443

–net=host is the recommended configuration for openHAB’s docker image. There are a lot more ports than just those two (discovery port, LSP port for VSCode syntax checking, etc), some bindings open their own ports, and many bindings require openHAB to be on the same subnet as the devices for discovery (e.g. Network, Shelly, Roku, etc.).

In order to have the smoothest operation of openHAB for the broadest audience the recommendation is to use --net=host. If you do want to map each port individually, you will have to research which ports your specific installation/configuration uses and forego the use of any binding that depends on openHAB being on the same subnet for discovery or operation which is probably more bindings than you may realize.

Well, i changed the ports of the other application to run on another port --> That worked out fine.

So i went back and started the docker container with standard settings:

docker run
–name openhab
–net=host
-v /etc/localtime:/etc/localtime:ro
-v /etc/timezone:/etc/timezone:ro
-v /opt/openhab/conf:/openhab/conf
-v /opt/openhab/userdata:/openhab/userdata
-v /opt/openhab/addons:/openhab/addons
-d
-e USER_ID=1001
-e GROUP_ID=9001
–restart=always
openhab/openhab:2.5.8

I still can’t reach openhab with the URL of my localhost machine, which hosts the containers.

Is openHAB fully started and ready? Look in openhab.log and make sure that something didn’t go wrong during startup. At a minimum there won’t be anything listening until you see something like “Dashboard started at …” lines in openhab.log. You will see similar log statements for each of the other UIs.

Hey, i have the following in my logs.

docker logs openhab
++ test -t 0
++ echo false
+ interactive=false
+ set -euo pipefail
+ IFS='
        '
+ '[' limited = unlimited ']'
+ rm -f /openhab/runtime/instances/instance.properties
+ rm -f /openhab/userdata/tmp/instances/instance.properties
+ NEW_USER_ID=1001
+ NEW_GROUP_ID=9001
+ echo 'Starting with openhab user id: 1001 and group id: 9001'
Starting with openhab user id: 1001 and group id: 9001
+ id -u openhab
++ getent group 9001
+ '[' -z '' ']'
Create group openhab with id 9001
+ echo 'Create group openhab with id 9001'
+ groupadd -g 9001 openhab
+ echo 'Create user openhab with id 1001'
Create user openhab with id 1001
+ adduser -u 1001 --disabled-password --gecos '' --home /openhab --gid 9001 openhab
Warning: The home dir /openhab you specified already exists.
Adding user `openhab' ...
Adding new user `openhab' (1001) with group `openhab' ...
adduser: Warning: The home directory `/openhab' does not belong to the user you are currently creating.
The home directory `/openhab' already exists.  Not copying from `/etc/skel'.
+ groupadd -g 14 uucp2
+ groupadd -g 16 dialout2
+ groupadd -g 18 dialout3
+ groupadd -g 32 uucp3
+ groupadd -g 997 gpio
+ adduser openhab dialout
Adding user `openhab' to group `dialout' ...
Adding user openhab to group dialout
Done.
+ adduser openhab uucp
Adding user `openhab' to group `uucp' ...
Adding user openhab to group uucp
Done.
+ adduser openhab uucp2
Adding user `openhab' to group `uucp2' ...
Adding user openhab to group uucp2
Done.
+ adduser openhab dialout2
Adding user `openhab' to group `dialout2' ...
Adding user openhab to group dialout2
Done.
+ adduser openhab dialout3
Adding user `openhab' to group `dialout3' ...
Adding user openhab to group dialout3
Done.
+ adduser openhab uucp3
Adding user `openhab' to group `uucp3' ...
Adding user openhab to group uucp3
Done.
+ adduser openhab gpio
Adding user `openhab' to group `gpio' ...
Adding user openhab to group gpio
Done.
+ initialize_volume /openhab/conf /openhab/dist/conf
+ volume=/openhab/conf
+ source=/openhab/dist/conf
++ ls -A /openhab/conf
+ '[' -z 'html
icons
items
persistence
rules
scripts
services
sitemaps
sounds
things
transform' ']'
+ initialize_volume /openhab/userdata /openhab/dist/userdata
+ volume=/openhab/userdata
+ source=/openhab/dist/userdata
++ ls -A /openhab/userdata
+ '[' -z 'cache
config
etc
logs
tmp' ']'
++ cmp /openhab/userdata/etc/version.properties /openhab/dist/userdata/etc/version.properties
+ '[' '!' -z ']'
+ chown -R openhab:openhab /openhab
+ sync
+ '[' -d /etc/cont-init.d ']'
+ sync
+ '[' false == false ']'
++ IFS=' '
++ echo gosu openhab tini -s ./start.sh
+ '[' 'gosu openhab tini -s ./start.sh' == 'gosu openhab tini -s ./start.sh' ']'
+ command=($@ server)
+ exec gosu openhab tini -s ./start.sh server
Launching the openHAB runtime...
++ test -t 0
++ echo false
+ interactive=false
+ set -euo pipefail
+ IFS='
        '
+ '[' limited = unlimited ']'
+ rm -f /openhab/runtime/instances/instance.properties
+ rm -f /openhab/userdata/tmp/instances/instance.properties
+ NEW_USER_ID=1001
+ NEW_GROUP_ID=9001
+ echo 'Starting with openhab user id: 1001 and group id: 9001'
Starting with openhab user id: 1001 and group id: 9001
+ id -u openhab
+ initialize_volume /openhab/conf /openhab/dist/conf
+ volume=/openhab/conf
+ source=/openhab/dist/conf
++ ls -A /openhab/conf
+ '[' -z 'html
icons
items
persistence
rules
scripts
services
sitemaps
sounds
things
transform' ']'
+ initialize_volume /openhab/userdata /openhab/dist/userdata
+ volume=/openhab/userdata
+ source=/openhab/dist/userdata
++ ls -A /openhab/userdata
+ '[' -z 'cache
config
etc
logs
tmp' ']'
++ cmp /openhab/userdata/etc/version.properties /openhab/dist/userdata/etc/version.properties
+ '[' '!' -z ']'
+ chown -R openhab:openhab /openhab
+ sync
+ '[' -d /etc/cont-init.d ']'
+ sync
+ '[' false == false ']'
++ IFS=' '
++ echo gosu openhab tini -s ./start.sh
+ '[' 'gosu openhab tini -s ./start.sh' == 'gosu openhab tini -s ./start.sh' ']'
+ command=($@ server)
+ exec gosu openhab tini -s ./start.sh server
Launching the openHAB runtime...

And what’s in openhab.log?

openhab.log was empty…

anyways, i switched from docker container and after a short cleanup, i got it running as “normal” linux installation :confused:

Thank you for trying to help me