How to configure the Home Assistant Docker container for mDNS?

I am looking to get the Home Assistant Docker container (specifically raspberrypi4-homeassistant) configured to resolve mDNS names, like the one generated by an Eagle-200 device.

On my host Raspberry Pi 4, I have no issues resolving the DNS name.
However, within the Docker container on that host, I cannot resolve it.
(I have no issues pinging public internet domains/DNS names from the host and the container.)

Is this a configuration that can be somehow added to the Home Assistant Docker image? Or only something that can be configured myself after pulling/running the Home Assistant Docker image?

# Successful ping with DNS name from host machine
pi@raspberrypi ~> ping eagle-xxxxxx.local
PING eagle-xxxxxx.local (192.168.1.6) 56(84) bytes of data.
64 bytes from 192.168.1.6 (192.168.1.6): icmp_seq=1 ttl=64 time=0.510 ms
64 bytes from 192.168.1.6 (192.168.1.6): icmp_seq=2 ttl=64 time=0.314 ms
^C
--- eagle-xxxxxx.local ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 0.314/0.412/0.510/0.098 ms


# Unsuccessful ping with DNS name from Docker container on host machine
pi@raspberrypi ~> docker exec -it homeassistant /bin/bash
bash-5.1# ping eagle-xxxxxx.local
ping: bad address 'eagle-xxxxxx.local'
bash-5.1# ping 192.168.1.6
PING 192.168.1.6 (192.168.1.6): 56 data bytes
64 bytes from 192.168.1.6: seq=0 ttl=64 time=0.720 ms
64 bytes from 192.168.1.6: seq=1 ttl=64 time=0.829 ms
^C
--- 192.168.1.6 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.720/0.774/0.829 ms


# Confirmed that Docker copied in the host's nameserver correctly
pi@raspberrypi ~> cat /etc/resolv.conf
# Generated by resolvconf
nameserver 192.168.1.1
...
pi@raspberrypi ~> docker exec -it homeassistant /bin/bash
bash-5.1# cat /etc/resolv.conf
# Generated by resolvconf
nameserver 192.168.1.1
...
1 Like

What kind of HA installation?
If it’s plain “Container”, be sure to use host networking or the multicast packets won’t go through.

Yes, it is a container installation, I thought that was the only Docker-centric one on Raspberry Pi.

Yes, the Docker command is copied from that page, docker run ... --network=host ..., which I believe allows the container to copy in the host’s /etc/resolv.conf file.

Hi! I am having the same issue. did you manage to figure this out?

1 Like

I did not :frowning:

Same problem :frowning:
Any news?

For me the solution was to include this on creating the container:

-v /volume2/docker2/homeassistant/config/resolv.conf:/etc/resolv.conf \

or in Docker compose:

volumes:
- “/volume2/docker2/homeassistant/config/resolv.conf:/etc/resolv.conf”

On the host, in the /etc/resolv.conf file, include your DNS server on the forst line:
nameserver 192.168.x.xxx

That worked for me.

For whoever comes here in relation to the title:

  1. That doesn’t do anything in relation mDns; mDns doesn’t use any DNS server, it’s a multicast based protocol
  2. That bind mount is specific to @WeterPeter. Nobody knows what is in the “/volume2/docker2/homeassistant/config/resolv.conf” file he mounts inside the HA container :wink:
  3. That breaks docker’s own DNS resolution mechanism. Your mileage might vary, here…

Bottom-line: Happy it works for him, but don’t try this at home :slight_smile:

For anyone that might stumble on this.
Should you decide not to use network_mode: host and instead make your own network for the container. The mDNS can be made working should used avahi reflectors in the configuration.
Just enable them in /etc/avahi/avahi-daemon.conf and restart the avahi daemon systemctl restart avahi-daemon.

2 Likes

Thanks, it helped. In gratitude, i detailed the changes for those users who are somewhat noobs with the console
I edited:

sudo nano /etc/avahi/avahi-daemon.conf

as show below:

[reflector]
enable-reflector=yes

then restarted the daemon:

sudo systemctl restart avahi-daemon

And now i can operate with Sonoff integrations in “local mode” without

--network=host

For the sake of completeness, be aware that enabling the reflector in the avahi configuration makes that mDNS will be reflected on ALL your interfaces.

While it is not a problem as such for most people, keep in mind that if you have more than one interface (e.g. a separate IoT subnet or VLAN), you can only have one reflector on these networks, otherwise they will start to re-advertise each other announcements!