Add avahi to base docker image

I’ve built this hack ErikApption/homeassistant-mdns: Custom Docker Image to add Avahi mDNS resolution to Home Assistant to add Avahi to the base image. I am happy to make a PR against the docker repo but wanted to get some feedback before. The issue with current mDNS is that:

  • many integrations like piper, mpd or shell rely on system name resolution - so you can’t use a .local name
  • I wrote a PR to add mDNS resolution using zeroconf to mpd but not sure this will move anywhere and this will not solve the issue for all integrations

The fix is really simple, add avahi in alpine and run the avahi daemon in background.

For what its worth, running HA Core container in HAOS, within the container I am able to ping devices using xxx.local. Taking a look at the processes running on HAOS, I see

root        2245    2157  0  2025 ?        00:00:00 s6-supervise mdns
root        2247    2245  0  2025 ?        00:04:20 mdns-repeater -f hassio

From this I came across the following:

So seems mDNS works with HAOS or supervised based installs, but if you are running just HA Core, then yeah I see your point.

I’m curious about this. Is the the idea to not run the Home Assistant container in host mode?

Not at all - this runs avahi inside the existing container so that the container can leverage system name resolution through avahi. Host mode is not sufficient for mDNS resolution, host mode only leverages the standard DNS not mDNS.

Awesome, going to investigate this to see if there is a way I could leverage the same setup inside my HA core setup.

I can understand this part - but even from that blog post, I’m unsure how the HA docker image can resolve mDNS names since there is no avahi or anything similar running inside the container. Only option I can imagine is that they hack the mDNS resolution into regular DNS using their custom DNS plugin?

I have a lot to learn. I thought host network mode put the containers on the host network and removed all isolation.

Are mDNS advertisements different than other Zeroconf? I just started up a HA container in host mode and it’s seeing my network.

And inside the container I can resolve .local addresses:

$ docker exec -it homeassistant bash
root@macha:/# ping -4 macha.local
PING macha.local (192.168.0.253) 56(84) bytes of data.
64 bytes from macha.local (192.168.0.253): icmp_seq=1 ttl=64 time=0.025 ms
64 bytes from macha.local (192.168.0.253): icmp_seq=2 ttl=64 time=0.032 ms
64 bytes from macha.local (192.168.0.253): icmp_seq=3 ttl=64 time=0.052 ms
^C

Oh, no, that’s the host. I cannot ping other machines.

@ottawahacker it looks like you are quite familiar with the mdns/zeroconf setup in Home Assistant and I ran into the same problem using podman and a rootless container.

One question:
Your Dockerfile installs not only avahi, but also dbus. I assume that this is how the successfull lookups are forwarded to HA?

I thought about setting up avahi on the host and forwarding avahi message via xdg-dbus-proxy to the container, do you think that would be possible? Do you have any idea where I can read more about that?