Using homekit component inside Docker

Just wanted to drop in here and post my solution. I’ve spent a lot of time getting a simple solution worked out, given the amount of time spent I feel that I must share.

Issue:
Running in network_mode: host would allow me to control my Ecobee3 Lite thermostat. This seems to use things related to mDNS, multicast, Bonjour, Homekit; I may be slightly wrong about that part.

How to pinpoint if you have the same issue:

  1. With Home Assistant running with network_mode: host, run:
docker exec [your home assistant docker container id here] python3 -m netdisco
  1. With Home Assistant running WITHOUT network_mode: host, run:
docker exec [your home assistant docker container id here] python3 -m netdisco

If #1 returns results but #2 does not, then you have the same situation as me and the solution below will probably work!

(side note: netdisco is documented here: https://www.home-assistant.io/integrations/homekit_controller/#home-assistant-cannot-discover-my-device)

Solution:
Add a container that repeats mDNS traffic from one network interface to another network interface. In my case I ran

docker exec [your home assistant docker container id here] ifconfig

and found that my Home Assistant container had a ip address of 192.168.80.7. To determine what network interface that’s on, I ran route -n and then found the 80 subnet (192.168.80.0) in the Destination column and then grabbed the interface name from the Iface column. I did the same for my host; find 0.0.0.0 and then grabbed the interface name from Iface.

Once you have the two network interface names, you can run a container to repeat mDNS between the two network interfaces.

Here’s a docker-compose example:

version: '3.8'

services:
  home-assistant:
    image: homeassistant/home-assistant
    ports:
    - 8123:8123

  mdns-repeater:
    image: angelnu/mdns_repeater
    network_mode: host
    environment:
    - hostNIC=enp4s0
    - dockerNIC=br-de87821a94e9

Also, here’s a link to my solution: https://github.com/TonyBrobston/tbro-server/blob/e3ff788e81c68848e20a5d325fe5c2e2484bf65d/home-automation/docker-compose.yml#L34-L40

I personally felt this was the best way to handle this problem, I feel like running network_mode: host on my Home Assistant container is opening up a bunch of things unbeknownst to me. I prefer to open only exactly as much as necessary. I realize that the mdns-repeater in my solution is running in network_mode: host, however I assume (probably a bad assumption) that the mdns-repeater isn’t doing anything more than repeating mDNS. I may look further into that repo later to be sure.

Hope this helps someone else!

8 Likes