Expose avahi socket to containers

If the /var/run/avahi-daemon/socket could be exposed to containers, one could easily do somename.local lookups from within a container by simply installing the libnss-mdns package.

Would simplify my CUPS container a lot

1 Like

Even being able to expose services via avahi would be really useful too - so people can create their own discovery tools etc

1 Like

Thanks for the request and interest all!

We’re going to discuss internally how we might implement this. In the meantime, there is a workaround which we’ll share below:

It should be possible to announce a server or service on the hostOS avahi using avahi-publish first you need to install avahi-publish, on debian it can be done like so:

RUN apt-get update && apt-get install avahi-utils

Then at run time you can run something like this:

# enable communication to hostOS dbus
export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket

avahi-publish -s $HOSTNAME _xxx._tcp 1883 "Status=Running" "Version=1.0" &> /dev/null &

replace xxx with whatever you want your service to be seen as and replace 1883 with the port you want it to tell other services it is listening on.

1 Like

But this is not what was asked:

one could easily do somename.local lookups from within a container

You are providing an address from within the container, not the same thing.

Hi @Timple,

Thank you for pointing this out.

We’ve put this on our roadmap to work on, but in the short term, can I advise an alternative work around?

You could install libnss-mdns and avahi utils within a container, and set the network_mode to host to get the same effect that the OP is asking for.

So having an ubuntu docker with network_mode: host and libnss-mdns and avahi-utils installed will allow me to ping other-hostname.local from within the container?

I am fairly sure this did not work, but perhaps it works in the meantime. We will try it and get back to you!

It’s pretty much what is done in this project: GitHub - balena-io/balena-mdns-publisher: MDNS address publisher for balena services