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.