Question regarding discovery with docker container

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:

---

- name: Create openhab user
  user:
    comment: 'openHAB'
    createhome: no
    name: openhab
    shell: /bin/false
    state: present
    system: yes
    uid: "{{ openhab_uid }}"

- name: Create /mnt/config/openhab
  file:
    path: /mnt/config/openhab
    state: directory
    owner: openhab
    group: openhab
    mode: a+rwx

- name: Create /mnt/config/openhab/conf
  file:
    path: /mnt/config/openhab/conf
    state: directory
    owner: openhab
    group: openhab
    mode: a+rwx

- name: Create /mnt/config/openhab/userdata
  file:
    path: /mnt/config/openhab/userdata
    state: directory
    owner: openhab
    group: openhab
    mode: a+rwx

- name: Create /mnt/config/openhab/addons
  file:
    path: /mnt/config/openhab/addons
    state: directory
    owner: openhab
    group: openhab
    mode: a+rwx

- name: create /mnt/config/openhab/.java
  file:
    path: /mnt/config/openhab/.java
    state: directory
    owner: openhab
    group: openhab
    mode: a+rwx

# todo pull down openhab config from gogs

- name: Start openHAB
  docker_container:
    detach: True
    devices:
      - "/dev/ttyUSB0:/dev/ttyUSB0:rwm"
    exposed_ports:
      - 8101
      - 8080
      - 8443
    hostname: chimera.koshak.net
    image: openhab/openhab:amd64
    log_driver: syslog
    name: openhab
    network_mode: host
    pull: True
    recreate: True
    restart: True
    restart_policy: always
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
      - /mnt/config/openhab/conf:/openhab/conf
      - /mnt/config/openhab/userdata:/openhab/userdata
      - /mnt/config/openhab/addons:/openhab/addons
      - /mnt/config/openhab/.java:/openhab/.java

- name: Allow openhab default port
  ufw:
    rule: allow
    to_port: 8080

- name: Allow openhab https port
  ufw:
    rule: allow
    to_port: 8443

- name: Add repo for the Oracle Java
 # apt_repository:
 #   repo: ppa:webupd8team/java
 #   state: present
  command: echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list

- command: echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list

- command: apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886

# TODO this isn't working when run from Ansible but does work when manually run with sudo
- name: Set the license acceptance
  command: echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections

- name: Install Java
  apt:
    name: oracle-java8-installer
    state: present

- name: Set environment variables
  apt:
    name: oracle-java8-set-default
    state: present
    update_cache: no

- name: Create /mnt/config/designer
  file:
    path: /mnt/config/designer
    state: directory
    mode: a+rwx

- name: Get Designer
  get_url:
    dest: /mnt/config/designer
    url: http://mirrors.xmission.com/eclipse/smarthome/releases/0.8.0/eclipsesmarthome-incubation-0.8.0-designer-linux64.zip

- name: Unzip Designer
  unarchive:
    src: /mnt/config/designer/eclipsesmarthome-incubation-0.8.0-designer-linux64.zip
    dest: /mnt/config/designer
    remote_src: True

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.

My intension is to run openhab as a container on a ubuntu server (NAS).

But when I do maintanace or something with my NAS, it would be great to move the container to my windows workstation for a while without any changes.

Creating a separate DNS entry would be a work around.
But I dont have a DNS server where I could created such an entry. :slight_smile:

After reading more docker documentation it looks like a dedicated ip is really not possible.
At least not in a simple way.

So it might not be woth it for my scenario.

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.

I know, thanks.

But then I had much more over head, just for the few times I would need to run openhab on another system.

Like I said, it looks like it is not woth it.

I know, but since these sorts of threads become a sort of permanent record I tend to leave responses directed at the future readers of these threads.

1 Like