openHAB 2 in Docker on a Raspberry Pi3

openHAB 2 in Docker on a Raspberry Pi3

Now that openHAB 2 is released I wanted to update my setup and also use the opportunity to try Docker. I’m pretty much a noob when it comes to linux, so it took me a while to get it running and I hope it’s up to muster.
The plan is to have openHAB 2 running in a Docker container, but have file persistence in the host file system. This way one can mess around in the container, delete it and build a new one while not loosing data.

So first the folders for persistence have to be created and given the appropriate rights:

sudo mkdir /opt/openhab/
sudo mkdir /opt/openhab/conf/
sudo mkdir /opt/openhab/userdata/
sudo mkdir /opt/openhab/addons/
sudo mkdir /opt/openhab/conf/items/
sudo mkdir /opt/openhab/conf/persistence/
sudo mkdir /opt/openhab/conf/rules/
sudo mkdir /opt/openhab/conf/scripts/
sudo mkdir /opt/openhab/conf/services/
sudo mkdir /opt/openhab/conf/sitemaps/
sudo mkdir /opt/openhab/conf/things/
sudo chown 9001.9001 /opt/openhab -R

Then the initial configuration files have to be copied into the host folders:

docker run --rm --user 9001 -v /opt/openhab/addons:/openhab/addons -v /opt/openhab/conf:/openhab/conf -v /opt/openhab/userdata:/openhab/userdata openhab/openhab:2.0.0-armhf sh -c 'cp -av /openhab/userdata.dist/* /openhab/userdata/ && p -av /openhab/conf.dist/* /openhab/conf/'

After that you can build the openHAB container with a normal run command:

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 \
--user=9001 \
--restart=always \
openhab/openhab:2.0.0-armhf

With the container running use the following command to access the Karaf shell (default password is habopen) :

ssh openhab@localhost -p 8101

Tailing logs can be achieved with:

log:tail

Raising or lowering the log level (list here):

log:set LEVEL package.subpackage
eg.: log:set DEBUG org.openhab.binding.zwave

Next up: running a mqtt and mysql container…

 

Links for reference:

http://docs.openhab.org/installation/docker.html

https://hub.docker.com/r/openhab/openhab/

Venedig 16 – Tag 16: Noch einmal alles, bitte
Test

Kommentar verfassen