I am thinking about using openhab2 as a docker container.
I have no experience with docker yet.
The official guide reads.
Important To be able to use UPnP for discovery the container needs to be started with --net=host.
As far as I understand that means openhab uses the IP of the host machine.
In case I want to move the container to another host, the IP for openhab will change too.
I think it would be nice to have a dedicated IP for openhab.
So I want to ask what “discovery” means exactly, to know the downside of using another network type.
Is it the discovery of new things and items, which was not present on OH1? (I think I could manage without that)
Or something with mDNS?
Or media playback (UPnP-AV)?
I think it has something to do with mDNS or UPNP and it lets the phone apps find OH on the network, though I’ve never really looked into it.
I have some experience running OH 2 in a docker container. I use Ansible to configure everything but I think you can figure out what I’m doing from the below ansible task:
The above creates a user, creates the config folders, pulls down and starts the container with the right parameters, updates UFW to allow those ports, and download and installs Java and Designer.
I’ve always run it with net host so I can’t say what it would mean if you didn’t. But even without net host and just using mapped ports the IP address of OH is the same as the IP of the host upon which the container is running. A container is not a VM so I don’t know know if it is possible to expose a container to your LAN with its own IP address.
However, this is what DNS is for. I actually use static IPs served through my DHCP server and a DNS server and all my local references to my server is done through the DNS name. So you could create a openhab.home.net DNS entry and just update the IP address in that entry when/if you move OH to another host.
Some limitations you will encounter:
you cannot use system ping or dhcplisten for the Network binding
you will not find the exec binding useful
you need to delete userdata/cache/* and userdata/tmp/* to force the add-ons to update when you update the image. Consequently I use addons.cfg to install addons instead of PaperUI and runtime.cfg for configuration parameters.
A VM might be an option. You could set up a Virtual Box or some other Type 2 hypervisor on both with a VM configured with bridged networking. This would make the VM look like a distinct computer on your network no matter where the VM is running.