Running openHAB 2 in Docker

docker
openhab2
Tags: #<Tag:0x00007f01542bf118> #<Tag:0x00007f01542bead8>

(Justus Reich) #62

It is about the avmfritz binding. I have configured through the addons.cfg file. The point where I am hanging is: In the addon.cfg file I only give the name of the binding and not its location:

# A comma-separated list of bindings to install (e.g. "sonos,knx,zwave")
binding = avmfritz,km1001,weather1,weatherunderground,zwave

How do I tell OH2 not to use the binding coming with the distribution but to use instead the one given in the addons folder?

EDIT: My addons folder is normally empty. Actually I do not know where OH2 gets the addons from as I thought they should be there :slight_smile: Anyway … I assume that I would put the new beta version of the binding into the addons folder and now I need to understand how to tell OH2 to use this instead off the official one.
Or can it be that the beta version has a different name???


(Rich Koshak) #63

You remove it from addons.cfg, wait for it to be uninstalled, then add the new jar to the addons folder.


(Justus Reich) #64

Does " … to be uninstalled, …" mean, that it does not appear anymore in the “bundle:list” command in the karaf console?

Sorry, for being stupid :slight_smile:


(Rich Koshak) #65

yes. you should also see logs saying that it is being removed.


(Justus Reich) #66

Thanks!!! Will do!


(Bert) #67

Hello all,
I would like to get some advice. I run openHAB on RPi2, and a second on a Banana Pro on an SSD drive. I only recently i came across docker and started to familiarize me with it.

I have a two questions. Using the tutorial in this tread i was able to get openhab running in a container with the config, addons and log files on the host file system. That works perfectly. Rich, thank you very much for this tutorial!
But my environment consists of Z-Wave and Sonoff devices.
My first question regards the z-wave config in a docker container. I use a Aeon Gen5 USB z-wave stick. Does anyone know if the USB/ttyACM0 device on the host will be available in the docker container? (I have not tried it yet, because i have only one stick and that is in use…)
My second question regards the use on mqtt (for Sonoff). The via this tut installed openHAB does not includes eg mosquitto.

Is it possible to add mosquitto to the openHAB container, either by installing it by hand in the openhab container and then save this as a new container? Or make use of docker-compose file and make a new container including the missing parts?
Or is it better to make a separate container for mosquitto (and for InfluxDb and for Grafana)? According to the docker directions one should create a separate container for every process that one uses.
But for me, it would be nice when i can backup one container with everything i use in openhab, this including InfluxDb, Grafana and mosquitto.

I am looking forward to your suggestions.
Btw, which containers for these products do you use for openhab? On the hub.docker.com i find multiple containers…


(Rich Koshak) #68

You have to make it available. --device=/dev/ttyUSB0 as an argument to docker run will make that device available in the container. See the command in “Running the container as a service” in the OP.

Correct. Mosquitto is a separate service which needs to be installed and configured separately. I use the official Mosquitto Image from Dockerhub.

This is counter to the purpose of Docker and considered a very bad practice. Each service should have its own container.

However, if you want to get into the business of building your own Docker images, there is nothing stopping you from creating such an image yourself.

You CAN write a docker-compose file that starts OH and Mosquitto in two separate containers which is not only supported but the expected way one would use docker-compose. I don’t use docker-compose so can’t help with the specifics. But docker-compose is used to start up and manage one or more docker containers, not build new Docker images.

This.

You should not be backing up containers. You should mount volumes into your container to keep the data that needs to be backed up and/or persisted. Containers are ephemeral. They are designed to be replacable and you need to treat all the files inside the container as temporary. Anything that needs to stick around even when a new container is created needs to be saves in a mounted volume. This is why you must mount your conf and userdata folder into the container. Otherwise there would be no way to upgrade the container because upgrading the image means changing the image and creating a new container…

I always use the official images. So for Mosquitto I use eclipses’ image. For InfluxDB I use InfluxDB’s image. For Grafana I use Grafana’s image. There is only one image I build myself (Calibre) and that is because there isn’t an official image and the existing images either didn’t work for me or worked in ways I didn’t like.


(Bert) #69

Hi Rich, Thank you for answering my questions.
I will forget about my idea to combine multiple services in one container. I have the eclipse-mosquitto now running as a separate container next to the openhab container.
Bert


(Pumbadinho) #70

Hi,

Currently planing my installation. I prefer docker, but I am not sure if everything will work.
I would for example like to shutdown my PC with Openhab. In another post they said that you need to install samba to do that. But in docker container there is no samba.
I just don’t want to limit myself. So this is a hard decision.

Any help? What won’t work with official docker container?


(Rich Koshak) #71

This makes no sense at all. Can you point me to that post?

Samba has nothing to do with one’s ability to shutdown the PC.

However, the whole point of a Docker Container is to isolate the container from the host machine. I would be shocked if you can call shutdown or reboot the host from inside the container. That would break the whole reason containers exist.

Just tried it. It won’t work. The shutdown and reboot commands cannot talk to the init daemon from inside the container. And I’d still argue that even if you could, you shouldn’t.

I’d also question the wisdom for OH to directly reboot the machine it is running on directly, but lots of people do it.

Generally, you will have to run as root and use host networking to use Network binding’s DHCP listen. You cannot use arping or system pings from the Network bindings, though there is an open issue to add that which I hope to work on this weekend. The exec binding and executeCommandLine will be pretty useless to you as there isn’t much installed in the Docker Image, is it should be, you want Containers to have as little installed as feasible. I’m sure there are other things that cannot be used as well.

However, given the nature of the question, I’m going to guess you don’t know much about Linux yet. Given that I’m going to strongly recommend using openHABian. You don’t have to be running on a RPi to use it. See the Manual Installation instructions.


(Pumbadinho) #72

I think there was a misunderstanding, I don’t want to restart the server… I want to restart my PC.
And the explanation why samba was required is because then you have an rpc package installed.


(Rich Koshak) #73

In that case, the answer is still no because there is no samba in the container.


(Marco Höfle) #74

Hello,
I am trying to move from a KVM VM to a docker container. The last feature missing is sending mails, apart from that everything works ok.
In addition to the openhab container packages I needed to install mysql-client.

On the VM I installed postfix and used localhost in the openhab mail config as I remember I had troubles there as well.

When I use my mail server directly (self signed certificate) I get:

17:46:50.807 [ERROR] [org.openhab.action.mail.internal.Mail] - Could not send e-mail to ‘…@…’.
org.apache.commons.mail.EmailException: Sending the email to the following server failed 192.168.xx.xx:25
.
.
.
Caused by: javax.mail.MessagingException: Could not convert socket to TLS
.
.
.
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

There was already a thread regarding this:


(Marco Höfle) #75

However, there was no solution


(Rich Koshak) #76

If you are using a self-signed cert you must add your CA to the JVM running inside the container. Java maintains its own collection of trusted CAs and will not trust your self-signed cert until you add your CA to the list.

I don’t know how to do this with Zulu which I’m pretty sure is the Java that comes in the docker image.


(Marco Höfle) #77

Thank you for the clarification.


(Marco Höfle) #78

I solved it by building a customised image with https://github.com/openhab/openhab-docker as a starting point.
I added postfix and bsd-mailx into print_basepackages() of the update.sh script.
The postfix config was changed, the hostname in mail.cfg points to localhost and that the docker container was restarted. This is the same setup as on the VM before.

A few questions came up:

  1. how to put the custom postfix config already into the docker image during built? This would avoid changing
    /etc/postfix/main.cf on the running container and restart it after a fresh build
  2. Connecting to knxd works with the -net=host option but not with --publish 3671:3671
    If multiple instances of openhab might run I guess the publish option is needed
  3. I needed to add “service postfix start” to entrypoint_debian.sh, is that the recommended way?

(Rich Koshak) #79
  1. You would have to add it to the Dockerfile to copy the config into the image during the build.

Alternatively, you can and probably should just mount your custom file as a volume. You can mount single files in addition to folders using the --volume flag.

  1. I don’t know anything about KNX so I can’t answer about that. But I can say that OH is not really designed to have multiple instances running on the same machine at the same time. And there are a bunch of other ports that would need to be moved around to make it work. Finally, if port 3671 is for the knxd then publishing that port on the Docker container is backwards. The container needs to be able to access that port, not accept connections on that port. What might be the problem is when you run without --net=host that your container has a different IP address from your host machine so you may need to use the IP address of your host if you are using localhost in the binding config.

  2. Well, the proper way would be to run postfix in a separate container and connect your containers with a custom network configuration. Containers are really intended to only run one service at a time. That is one of the distinctions between containers and VMs. I know it is possible to run multiple services inside a container but I don’t know how that is done. I’d say to try it and see what happens.


(Capo) #80

Hey there

Sorry for replying to an old post.
The access wih docker exec works

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

But!
If i want to use Visual studio to access the karaf console i cant.
Cos the ssh access does not work ether

ssh openhab@<IPAdress> -p 8101

Iam using Docker in Bridge mode.
Any solution on this?


(Rich Koshak) #81

You have to change the karaf console config to allow connections from addresses other than localhost. https://docs.openhab.org/administration/console.html#bind-console-to-all-interfaces