Hi,
This topic is for those of you trying to run Docker containers that use python-zeroconf and get the error messages like “[Errno 98] Address already in use”.
Example are the HomeAssistant and ESPHome containers.
Context:
HomeAssistant requires to set the network mode as host, meaning that all ports that are open by the container will be bind to the hosts (in this case CE) interface.
The missing information is that HomeAssistant auto discovery uses python-zeroconf that needs to bind to UDP port 5353, that is the port used for nDNS, zeroconf, avahi, bonjour (whatever you want to call it)
But by default CE’s avahi-daemon configuration denies to have multiple processes binding to that port, as per: https://github.com/CoreELEC/CoreELEC/blob/2d16550a390c8e93815d07a113aadb7dc4632811/packages/network/avahi/package.mk#L60
Solution:
Solution 1: the neatest solution would be to open a PR to change the default value but despite the age of the comment (2013) I’m afraid that it would cause issues to some users.
Solution 2: But there’s a workaround, one just need to have a configuration file that allows multiple processes to bind to the above mentioned UDP port and restart the avahi-daemon with this new file.
Run:
cp /etc/avahi/avahi-daemon.conf /storage/.config/avahi-daemon.conf
sed -e "s,^.*disallow-other-stacks=.*$,disallow-other-stacks=no,g" -i /storage/.config/avahi-daemon.conf
Create the file /storage/.config/system.d/avahi-daemon-stacks.service with the contents:
[Unit]
Description=Avahi Daemon
After=network.target avahi-defaults.service
Requires=avahi-defaults.service
ConditionPathExists=/storage/.cache/services/avahi.conf
[Service]
Restart=on-failure
EnvironmentFile=-/run/libreelec/debug/avahi.conf
ExecStart=/usr/sbin/avahi-daemon -f /storage/.config/avahi-daemon.conf -s $AVAHI_DEBUG
ExecReload=/usr/sbin/avahi-daemon -r
TimeoutStopSec=1s
RestartSec=2
StartLimitInterval=60
StartLimitBurst=10
[Install]
WantedBy=multi-user.target
And finally, create a /storage.config/autostart.sh if you don’t have one yet, don’t forget to add execution bit (chmod +x /storage.config/autostart.sh) and add the followinf to it:
(
systemctl stop avahi-daemon
sleep 2
systemctl start avahi-daemon-proxy
) &
Hope it works for you, good luck