Hi @krital ,
There’s definitely a way to programmatically publish and withdraw services.
I’ve never used the mdns NPM module, but it does look like it relies on avahi-daemon running to operate, which means you’d need it in your container and using host networking (this won’t work over the Docker bridge). Did you enable host networking for the service publishing the services?
An alternative would be to hook into the host instance of Avahi using DBus from within your service, and then use this to publish/withdraw services as required. I haven’t actually got an example using services, but we have created something similar to publish hostnames in the following project: https://github.com/balena-io/balena-mdns-publisher
https://github.com/balena-io/balena-mdns-publisher/blob/master/src/app.ts shows how we use a DBus NPM module in TypeScript to communicate with the underlying host OS Avahi instance to publish hostnames. However, the DBus API for service publishing is very similar and you should be able to swap out the call to AddAddress with AddService with relevant parameters for this to work (and similarly for withdrawing services).
I have just found a quick Python example here: https://stackoverflow.com/questions/1534655/creating-a-program-to-be-broadcasted-by-avahi so you should be able to use the same parameter list.
Best regards, Heds