Public Repository

Last pushed: 3 hours ago
Short Description
openHAB - a vendor and technology agnostic open source automation software for your home.
Full Description

openHAB2 Docker Containers

Table of Contents

Introduction

Repository for building Docker containers for openHAB (Home Automation Server). Comments, suggestions and contributions are welcome!

Image Variants

openhab/openhab:<version>-<architecture>

Version

Architecture:

  • amd64 for most desktop computer (e.g. x64, x86-64, x86_64)
  • armhf for ARMv7 devices 32 Bit (e.g. most RaspberryPi 1/2/3)
  • arm64 for ARMv8 devices 64 Bit (not RaspberryPi 3)

If you are unsure about what your needs are, you probably want to use openhab/openhab:2.0.0-amd64.

Prebuilt Docker Images can be found here: Docker Images

Usage

Important: To be able to use UPnP for discovery the container needs to be started with --net=host.

The following will run openHAB in demo mode on the host machine:

docker run -it --name openhab --net=host openhab/openhab:2.0.0-amd64

NOTE: Although this is the simplest method to getting openHAB up and running, but it is not the prefered method. To properly run the container, please specify a host volume for the directories.

Starting with Docker named volumes (for beginners)

Following configuration uses Docker named data volumes. These volumes will survive, if you delete or upgrade your container. It is a good starting point for beginners. The volumes are created in the Docker volume directory. You can use docker inspect openhab to locate the directories (e.g. /var/lib/docker/volumes) on your host system. For more information visit Manage data in containers:

Running from command line

docker run \
        --name openhab \
        --net=host \
        -v /etc/localtime:/etc/localtime:ro \
        -v /etc/timezone:/etc/timezone:ro \
        -v openhab_addons:/openhab/addons \
        -v openhab_conf:/openhab/conf \
        -v openhab_userdata:/openhab/userdata \
        -d \
        --restart=always \
        openhab/openhab:2.0.0-amd64

Running from compose-file.yml

Create the following docker-compose.yml and start the container with docker-compose up -d

openhab:
  image: "openhab/openhab:2.0.0-amd64"
  restart: always
  net: host
  volumes:
    - "/etc/localtime:/etc/localtime:ro"
    - "/etc/timezone:/etc/timezone:ro"
    - "openhab_addons:/openhab/addons"
    - "openhab_conf:/openhab/conf"
    - "openhab_userdata:/openhab/userdata"
  environment:
    OPENHAB_HTTP_PORT: "8080"
    OPENHAB_HTTPS_PORT: "8443"

Running openHAB with libpcap support

You can run all openHAB images with libpcap support. This enables you to use the Amazon Dashbutton Binding in the Docker container. For that feature to work correctly, you need to run the image as root user. Create the following docker-compose.yml and start the container with docker-compose up -d

openhab:
  container_name: openhab
  image: "openhab/openhab:2.0.0-amd64"
  restart: always
  net: host
  cap_add:
    - NET_ADMIN
    - NET_RAW
  volumes:
    - "/etc/localtime:/etc/localtime:ro"
    - "/etc/timezone:/etc/timezone:ro"
    - "openhab_conf:/openhab/conf"
    - "openhab_userdata:/openhab/userdata"
    - "openhab_addons:/openhab/addons"
  # The command node is very important. It overrides
  # the "gosu openhab ./start.sh" command from Dockerfile and runs as root!
  command: "./start.sh"

If you could provide a method to run libpcap support in user mode please open a pull request.

Starting with Docker mounting a host directory (for advanced user)

You can mount a local host directory to store your configuration files. If you followed the beginners guide, you do not need to read this section. The following run command will create the folders and copy the initial configuration files for you.

docker run \
  --name openhab \
  --net=host \
  -v /etc/localtime:/etc/localtime:ro \
  -v /etc/timezone:/etc/timezone:ro \
  -v /opt/openhab/addons:/openhab/addons \
  -v /opt/openhab/conf:/openhab/conf \
  -v /opt/openhab/userdata:/openhab/userdata \
  openhab/openhab:2.0.0-amd64

Accessing the console

You can connect to a console of an already running openHAB container with following command:

  • docker ps - lists all your currently running container
  • docker exec -it openhab /openhab/runtime/bin/client - connect to openHAB container by name
  • docker exec -it c4ad98f24423 /openhab/runtime/bin/client - connect to openHAB container by id

The default password for the login is habopen.

Debug Mode

You can run a new container with the command docker run -it openhab/openhab:2.0.0-amd64 ./start_debug.sh to get into the debug shell.

Environment variables

  • EXTRA_JAVA_OPTS=""
  • LC_ALL=en_US.UTF-8
  • LANG=en_US.UTF-8
  • LANGUAGE=en_US.UTF-8
  • OPENHAB_HTTP_PORT=8080
  • OPENHAB_HTTPS_PORT=8443
  • USER_ID=9001

By default the openHAB user in the container is running with:

  • uid=9001(openhab) gid=9001(openhab) groups=9001(openhab)

Parameters

  • -p 8080 - the port of the webinterface
  • -v /openhab/addons - custom openhab addons
  • -v /openhab/conf - openhab configs
  • -v /openhab/userdata - openhab userdata directory
  • --device=/dev/ttyUSB0 - attach your devices like RFXCOM or Z-Wave Sticks to the container

Building the image

Checkout the github repository and then run these commands:

$ docker build -t openhab/openhab .
$ docker run -it openhab/openhab server

Contributing

Contribution guidelines

License

When not explicitly set, files are placed under .

Docker Pull Command
Owner
openhab

Comments (19)
cniweb
5 months ago

Please note:
Issues are to be submitted here:
https://github.com/openhab/openhab-docker/issues

hardoverflow
5 months ago

Whats the problem ?

karaf: KARAF_ETC is not valid: /openhab/userdata/etc

Problem appears when i use:
-v /path/to/conf:/openhab/conf
-v /path/to/userdata:/openhab/userdata

Container Linux by CoreOS alpha (1298.1.0)

ryanram
5 months ago

docker exec -it openhab /openhab/runtime/bin/client

Default password is habopen

henfri
5 months ago

I think, the reason is, that OpenHAB nows the variable:
HTTP_PORT
and
HTTPS_PORT

Whereas the documentation on docker-hub says:
OPENHAB_HTTP_PORT and OPENHAB_HTTPS_PORT

With HTTP_PORT it does seem to work here.

Could someone check this and update the documentation above accordingly?

henfri
5 months ago

And one more thing:

docker exec -it c4ad98f24423 /openhab/runtime/bin/client - connect to given container by id

Could you please add the (default) password for this way to access openhab?

henfri
5 months ago

I just observed, that while I specify the environment variable
OPENHAB_HTTPS_PORT: "8444"
the https port that is opened is 8443
But when I access this, I get (in Chrome)
ERR_EMPTY_RESPONSE

The OPENHAB_HTTP_PORT seems not be opened at all

henfri
5 months ago

Hello,

shouldn't the web-interface be accessible over one of the specified ports after the start of the container?

After starting the container, I see these ports newly opened:
< tcp6 0 0 127.0.0.1:8101 ::: LISTEN 32318/java
< tcp6 0 0 127.0.0.1:46413 :::
LISTEN 32318/java
< tcp6 0 0 :::8443 ::: LISTEN 32318/java
< udp6 0 0 172.17.0.1:36102 :::
32318/java
< udp6 0 0 :::5353 ::: 32318/java
< udp6 0 0 :::5353 :::
32318/java
< udp6 0 0 192.168.177.3:46405 ::: 32318/java
< udp6 0 0 :::1900 :::
32318/java
< udp6 0 0 :::1900 :::* 32318/java

I am running the container with this docker-compose.yml:
openhab:
image: "openhab/openhab:2.0.0-amd64"
restart: always
net: host
volumes:

- "/etc/localtime:/etc/localtime:ro"
- "/etc/timezone:/etc/timezone:ro"
- "/srv/Daten/dockerconfig/knx/openhab/userdata:/openhab/userdata"
- "/srv/Daten/dockerconfig/knx/openhab/conf:/openhab/conf"

environment:
OPENHAB_HTTP_PORT: "8082"
OPENHAB_HTTPS_PORT: "8444"
command: server
user: "997"

Greetings,
Hendrik

nzbuu
5 months ago

Ah. I see in the docker instructions it says:

"-v /opt/openhab/addons:/openhab/addons : only needed if installing addons unavailable via PaperUI or the Karaf Console"

cniweb
5 months ago

We adapt the documentation accordingly!