Running openHAB 2 in Docker

yes, it looks to see if certain files exist and if not copies over the default set.

openhab | mmap failed for CEN and END part of zip file
openhab | Error installing bundle listed in startup.properties with url: mvn:org.apache.karaf.features/org.apache.karaf.features.extension/4.2.7 and startlevel: 1

Google lists a lot of errors concerning mmap. Mainly if an out of memory condition occurs. Maybe you do not have enough memory on your OMV5 machine?

Hi,
I managed to get OpenHAB working with macvlan support in docker to be able to have multiple UPNP servers on one host. Although this had been already discussed in 2017 it took me quite some time to figure out how this actually works and can be configured. Therefore I would like to share my findings to save time for others that are looking for a solution for the same problem.

Problem - Why I want to run OpenHAB with own IP and MAC inside a Docker container

OpenHAB recommends the docker network mode “host” mosty because it runs an UPNP server for autodetection purposes. This blocks port 1900 systemwide, so if you want to run another docker container with plex or jellyfin or minidlna you will get the error “port already in use”.

Solution

Macvlan allows to create a new network interface with own IP address an own mac. The downside is that macvlan in docker only allows connections to other server and not to the host it’s running on. Therefore it has to be included in the setup and we will end up in creating a separate subnet in docker that can be used for these types of installations.

Overview

  1. Set up an external macvlan network interface in docker
  2. Use this network for the OpenHAB container
  3. Set up an interface on the host for communication with the docker subnet

Create external Docker macvlan network

In my case I run a C-class network 192.168.1.0 in my home and my DHCP server assigns addresses in the range 192.168.1.50 to 192.168.1.100. So I decided to use the subnet 192.168.1.224/28 (IPs 192.168.1.224 to 192.168.1.239) for these special docker containers.
You can’t use the full subnet as the first and last address can’t be used. The 192.168.1.238 address will be the interface to the host. More about that below. Now we will have 13 usable IP addresses for Docker containers with the option to run a macvlan. This is enough for me. You can expand the range very easily by yourself.

Now we create the docker macvlan as an external network to be able to share it between the containers. If you define it in the docker run command you will run into an error if you fire up a second container because the gateway can only be defined once.

docker network create -d macvlan --subnet 192.168.1.0/24 --ip-range=192.168.1.224/28 --aux-address 'host=192.168.1.238' --gateway 192.168.1.1 -o parent=eth0 mac-vlan

Explanation

-d macvlan: Docker macvlan network driver
–address ‘host=192.168.1.238’: This IP address is excluded from the docker internal DHCP server that would assign an address if we wouldn’t specify it in the run definition
–gateway 192.168.1.1 is the default gateway of my host system - never tried it without
-o parent eth0: The mac-vlan network is a sub-network connected to eth0 which is the main network card of my host

Use the network in the container

I only use docker-compose. Here

  1. remove the network_mode: host definition
  2. add a new networks section like this. My host now has IP 192.168.1.230 and uses mac-vlan created above
version: "2"
services:
  openhab:
    image: "openhab/openhab:latest"
#    network_mode: host
 ------ omitted unimportant lines ------ 
    networks:
      openhab_mac_net:
        ipv4_address: 192.168.1.230

networks:
  openhab_mac_net:
    external:
      name: mac-vlan

Set up the host system

To connect the container subnet to the host we have to take the following steps:

  1. create a macvlan interface on the host
  2. add a route on the host to the docker subnet

I have an Ubuntu host. Therefore the following section may vary for other distributions.

Command line (temporary)

sudo ip link add macvlan-docker link eth0 type macvlan mode bridge
Creates a macvlan interface with the name macvlan-docker linked to eth0 on my host.

sudo ip addr add 192.168.1.238/32 dev macvlan-docker
Assigns the IP address 192.168.1.238 to the newly created interface. This is why we had to exclude it when creating the macvlan network in Docker.

sudo ip link set macvlan-docker up
We have to bring the interface up before we can add a route

sudo ip route add 192.168.1.224/28 dev macvlan-docker
Creates a route for the subnet 192.168.1.224/28 via the interface created above

Now we are done and we can fire up the container. It will appear like an physical server in the network.

Caution! The ip commands above are not permanent and don’t survive a reboot. Therefore I added the host network definition in my /etc/networks/interfaces on my Ubuntu system.

Permanent definition in /etc/networks/interfaces

# macvlan interface for docker
auto macvlan-docker
iface macvlan-docker inet static
   address 192.168.1.238
   netmask 255.255.255.240
   network 192.168.1.224
   pre-up ip link add name macvlan-docker link eth0 type macvlan mode bridge
   post-down ip link del dev macvlan-docker

That’s it. I hope it helps and please let me know if something is unclear in my description.

My main sources (in German) were https://blog.oddbit.com/post/2018-03-12-using-docker-macvlan-networks/ and https://www.foxplex.com/sites/virtuelle-netzwerkschnittstellen-unter-linux-mit-macvlan/

2 Likes