Running openHAB 2 in Docker

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?

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.

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.

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

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:

However, there was no solution

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.

Thank you for the clarification.

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?
  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.

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?

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

2 Likes

Thanks a lot!
Champ!

Hello Rich,
you are right, having a separate container for postfix is the more elegant solution.
Thanks
Marco

Thank you very much :slight_smile: Now i just gonna get my Tellstick working :slight_smile:

Hi,
Newbie here.
Running Ubuntu 16.04 as VM under esxi 6, ad have installed docker CE, and pulled the openhab 2.2.0 amd64 debian image.
How to I get attach my gen 5 Z stick ( which shows up as Bus 2 Device 004 ID xxxx:xxxx Sigma Designs) to the openhab docker? And for that matter, how to do so for the Telegesis Zig Bee USB stick?

thanks!

Passthrough the USB devices to the VM.

They will show up as /dev/ttyUSB? where ? is a number… You will have to figure out which number is which USB device.

Use the --device option to docker run, e.g. --device=/dev/ttyUSB0 as described in the readme for the image on dockerhub and github.

1 Like

Unfortunately my motherboard, an Intel S1200kp does not allow VT-D and I cannot passthrough. But I can attach the USB device to the VM. Will that work as well?
when I do a lsusb command , it only shows up in the way I have described

Thanks for your help.

If it doesn’t show up as a file under /dev as a try file then the bindings can’t access it whether or not you are running in Docker.

Found it! its /dev/ttyACM0

How do I automatically add the z stick whilst creating the docker openhab container?