- Pulling the Docker Image
- Preparing the System
- Running the Container
- Automating Docker setup using Ansible
Pulling the Docker Image
The OpenHAB 3 image is available on Docker Hub:
docker pull openhab/openhab:3.1.0-snapshot-alpine
Preparing the System
groupadd -g 9001 openhab
useradd -g 9001 openhab
usermod -a -G openhab myownuser
mkdir -p /opt/openhab/{openhab_addons,openhab_conf,openhab_userdata}
chmod -R 775 /opt/openhab
Running the Container
From your commandline:
docker run \
--name openhab \
--net=host \
--privileged \
--rm \
-v /etc/localtime:/etc/localtime:ro \
-v /opt/openhab/openhab_addons:/openhab/addons \
-v /opt/openhab/openhab_conf:/openhab/conf \
-v /opt/openhab/openhab_userdata:/openhab/userdata \
-d \
openhab/openhab:3.1.0-snapshot-alpine
In docker-compose:
version: "3.8"
services:
openhab:
image: "openhab/openhab:3.1.0-snapshot-alpine"
restart: always
network_mode: host
volumes:
- "/etc/localtime:/etc/localtime:ro"
- "/etc/timezone:/etc/timezone:ro"
- "/opt/openhab/openhab_addons:/openhab/addons"
- "/opt/openhab/openhab_conf:/openhab/conf"
- "/opt/openhab/openhab_userdata:/openhab/userdata"
environment:
OPENHAB_HTTP_PORT: "8181"
OPENHAB_HTTPS_PORT: "8443"
EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Berlin"
I changed the HTTP port to 8181 - as I am already using the default port 8080 for a different service. Make sure the port is accessible from your LAN:
ufw allow 8181/tcp
Automating Docker setup using Ansible
You can test it by running:
ansible-playbook -i mycontainerhost, -t openhab run-containers.yml
- name: OpenHAB v3 Container
hosts: test
gather_facts: no
tasks:
- name: Run OpenHab Container
tags: openhab
docker_container:
name: openhab
image: openhab/openhab:3.1.0-snapshot-alpine
state: started
detach: yes
interactive: yes
tty: yes
ports:
- 8181:8080
- 8101:8101
- 5007:5007
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- /opt/openhab/addons:/openhab/addons
- /opt/openhab/conf:/openhab/conf
- /opt/openhab/userdata:/openhab/userdata
keep_volumes: yes
hostname: openhab.localnet
memory: 512m
pull: true
restart_policy: unless-stopped
env:
EXTRA_JAVA_OPTS="-Duser.timezone=Europe/Berlin"
Run the playbook and visit the IP address of your server on port 8181:
Choose the bindings that you will need to be installed:
Maintenance
Clean Up when things go wrong
Delete the contents of /opt/openhab/userdata/cache
and /opt/openhab/userdata/tmp
rm -rf /opt/openhab/userdata/cache
rm -rf /opt/openhab/userdata/tmp
OpenHAB CLI
Access the OpenHAB command line tool inside the Docker container from your host system:
docker exec -it openhab /openhab/runtime/bin/client
Logging in as openhab
Password: PASSWORD IS habopen
_ _ _ ____
___ ___ ___ ___ | | | | / \ | __ )
/ _ \ / _ \ / _ \ / _ \ | |_| | / _ \ | _ \
| (_) | (_) | __/| | | || _ | / ___ \ | |_) )
\___/| __/ \___/|_| |_||_| |_|/_/ \_\|____/
|_| 3.1.0-SNAPSHOT - Build #2099
Use '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
To exit, use '<ctrl-d>' or 'logout'.
openhab>
Accessing the OpenHab logs from the CLI:
openhab> log:tail