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`
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# 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
dialout:x:18:openhab,scott,nut,apache,nginx
openhab:x:1000:openhab,scott
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
#!/bin/bash
if [ $# -lt 1 ]; then
CONTAINER_NAME="openhab"
OH_NAME="openhab/openhab:2.5.5-snapshot-amd64-debian"
else
CONTAINER_NAME="$1"
OH_NAME="casabot:5000/${CONTAINER_NAME}"
fi
#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 -Dgnu.io.rxtx.SerialPorts=${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 \
${OH_NAME}
Hope this helps!