How run OpenHab 2 in docker with working Hue emulation (alexa integration)

I recently moved an existing OpenHab installation to docker as a part of redoing a server setup. It works well so far but I ran into one issue: I do need the Hue emulation to work for Alexa integration. From what I read (and noticed in the past) that seems to only work if it is reachable from port 80.

How can I get that to work with docker-compose? Setting network mode to host and OPENHAB_HTTP_PORT to 80 is not working with a permission denied error. Removing network mode host and adding port 80:8080 does not seem to work either.

My only other clue would be to use port 8080 and do a port redirection from 80 to 8080 on the host. Has anyone else figured this out?

I use nginx to do it. I am not in docker though. The hue emulation docs site how to setup a redirect again not in docker.

For docker though I thought you could do it as part of the launch for the docker container. Basically you specified the docker port mapped to the host port? Am i wrong?

Probably because there is another service running on port 80.
You should double check this.

In your compose file you can use either network=host with OPENHAB_HTTP_PORT=80 or only port-redirection 80:8080 and 1900:1900/udp. The first is preferable.

1 Like

Thank you for the answers. I changed my OpenHab docker-compose file to 80:8080 and 1900:1900/udp but unfortunately I still get the Could not join upnp multicast network! error when starting the pairing process.
I set the Optional Discovery Address to the IP address of the server hosting the docker containers and http://ip.of.the.server/api/status is showing everything looking fine other than upnp announcement thread not running
Do I have to switch to host mode?

Ok, I tried to switch to host mode and changed the HTTP port of openhab to 80 (for Hue emulation) and all I got was a lot of errors from OpenHab Permission denied. There is no other service running on Port 80. Using it with docker-compose and forward it to 8080 for Openhab worked without a problem.

This is a very annoying combination of errors ;( I have no idea how to get OpenHab and Hue emulation running in Docker like this

Why not just run openHAB without docker? Know that works flawlessly.

Because the same server is running a lot of other software too and docker makes the setup super portable. It will be my last resort but it should really work with docker too. Running in hostmode is not that different from a direct installation

Under linux, port 80 (any port less than 1024, IIRC), is a privileged port. To get around this and other issues, I use iptables to NAT port 80 to port 8080, which is the default port on which openHAB listens for HTTP requests. I set up the NAT’ing of port 80 -> 8080 via rc.local (my docker machine boots CentOS 7.) Note that for rc.local to be executed on boot, I had to enable execute permission of /etc/rc.d/rc.local by running the command:

sudo chmod +x /etc/rc.d/rc.local

Permissions of /etc/rc.local (/etc/rc.d/rc.local):

[scott@casabot ~]$ ls -l `readlink -f /etc/rc.local`
-rwxr-xr-x 1 root root 563 Oct 20  2019 /etc/rc.d/rc.local

Contents of /etc/rc.d/rc.local:

[scott@casabot ~]$ cat `readlink -f /etc/rc.local`
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

/sbin/iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080

touch /var/lock/subsys/local

The OH2 container runs as user openhab. UID and GID of openhab:

[scott@casabot ~]$ fgrep openhab /etc/passwd
openhab:x:1000:1000:OpenHAB User:/home/openhab:/bin/bash
[scott@casabot ~]$ fgrep openhab /etc/group

I prefer to launch the OH2 container via a bash script, as I can easily handle USB port assignments, /dev/ttyUSBzigbee and /dev/ttyUSBzwave on the host system. I use docker network host mode.

OH2 container launch script:

[scott@casabot ~]$ cat ~openhab/oh/start-oh-snapshot

if [ $# -lt 1 ]; then

#ZIGBEE_TTY=`readlink -f /dev/ttyUSBzigbee`
ZWAVE_TTY=`readlink -f /dev/ttyUSBzwave`

docker run \
    --name ${CONTAINER_NAME} \
    --tty=true \
    --net=host \
    --device=${ZWAVE_TTY} \
    -v /etc/localtime:/etc/localtime:ro \
    -v /home/openhab/oh/timezone:/etc/timezone:ro \
    -v /home/openhab/oh/openhab_addons:/openhab/addons \
    -v /home/openhab/oh/openhab_conf:/openhab/conf \
    -v /home/openhab/oh/openhab_userdata:/openhab/userdata \
    --env="EXTRA_JAVA_OPTS=-Xms750m -Xmx1500m -Duser.timezone=America/Denver${ZWAVE_TTY} -Xbootclasspath/a:/openhab/conf/automation/jython/jython-standalone-2.7.0.jar -Dpython.home=/openhab/conf/automation/jython -Dpython.path=/openhab/conf/automation/lib/python" \
    --env="USER_ID=1000" \
    --env="GROUP_ID=1000" \
    -d \
    --restart=no \

Hope this helps!

1 Like

Thank you very much @scottk while I don’t really love having to run OpenHab in host mode this seems to work. At least no log errors, I will try searching for new devices later

Hi, is there a new Solution with OH3. I run this in a qnap docker even on port 80 without any problems but can not get hue emulation to work. No Connection to Alexa neither free@home. Help is appreciated
Best Ragards