# Balena Supervisor & Avahi

**URL:** <https://forums.balena.io/t/balena-supervisor-avahi/23956>\
**Category:** Product support\
**Created:** [August 10, 2019, 12:13pm UTC](https://forums.balena.io/t/balena-supervisor-avahi/23956 "2019-08-10T12:13:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![krital](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/krital/32/1349_2.png) [@krital](https://forums.balena.io/u/krital)\
**Post date:** [August 10, 2019, 12:13pm UTC](https://forums.balena.io/t/balena-supervisor-avahi/23956/1 "2019-08-10T12:13:55Z")

</div>

Hello,

it seems that in the latest versions of the balena OS the supervisor is using Avahi on the host OS. If one has a multi container project, I understand that they do not need avahi in the container but they can somehow tell the supervisor about the services they launch. I have seen the zoo publisher but this creates a static service file, what if the software I run in the containers already supports avahi? Can I not take advantage of that?

I wish there was a single variable that could instruct the supervisor to publish ports for each container to avahi, anyone has tried anything similar?

---

<div class="post-metadata">

**Author:** ![CameronDiver](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@CameronDiver](https://forums.balena.io/u/CameronDiver)\
**Post date:** [August 12, 2019, 2:34pm UTC](https://forums.balena.io/t/balena-supervisor-avahi/23956/2 "2019-08-12T14:34:49Z")

</div>

Hey @krital,

I’d like to understand a little better what you are trying to achieve and then work through it with you 🙂

So all balena devices will advertise themselves as `<short-uuid>.local`. This will obviously just resolve to the device’s local address.

Now this means that any ports you expose (using the docker-compose `expose` or `ports` fields) should be accessible over this address.

Does this clear things up for you? If not understanding exactly what you’re trying to do would be helpful.

---

<div class="post-metadata">

**Author:** ![krital](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/krital/32/1349_2.png) [@krital](https://forums.balena.io/u/krital)\
**Post date:** [August 12, 2019, 2:55pm UTC](https://forums.balena.io/t/balena-supervisor-avahi/23956/4 "2019-08-12T14:55:37Z")

</div>

Hi Cameron,

thanks for the response. I have a multi container project running on a balena fin 1.0 where several of the containers should expose services over MDNS / Avahi. So far:

1. The host id.local is advertised by host os
2. The zoo publisher example also advertises its services. However it using SystemD and creates an avahi service file.
3. I have a node js application that uses the mdns npm module but it exposes programmatically its services and has no systemd.

What seems to happen is that I can see all service definitions in the subnet (using Discovery on a Mac) but the ones from the container on item 3 above have 0 items.

Do I have to mimic the zoo example or can I somehow programmatically tell the avahi daemon about these services?

Thanks in advance,

Alex Kritikos

---

<div class="post-metadata">

**Author:** ![CameronDiver](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@CameronDiver](https://forums.balena.io/u/CameronDiver)\
**Post date:** [August 12, 2019, 3:18pm UTC](https://forums.balena.io/t/balena-supervisor-avahi/23956/5 "2019-08-12T15:18:09Z")

</div>

Hey @krital, I see what you mean now. I think what’s probably best is if I reach out to @hedss about this, as he wrote the zoo publisher example and has a bunch of experience working with avahi, so if anybody knows it would be him.

He’s currently on time off, ending tomorrow, so he should be able to reply in the next day or two. Until then it might be worth posting the code you’re using for a reference.

---

<div class="post-metadata">

**Author:** ![hedss](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/hedss/32/210_2.png) [@hedss](https://forums.balena.io/u/hedss)\
**Post date:** [August 13, 2019, 9:17am UTC](https://forums.balena.io/t/balena-supervisor-avahi/23956/9 "2019-08-13T09:17:02Z")

</div>

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)  
[https://github.com/balena-io/balena-mdns-publisher/blob/master/src/app.ts](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](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

---

<div class="post-metadata">

**Author:** ![krital](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/krital/32/1349_2.png) [@krital](https://forums.balena.io/u/krital)\
**Post date:** [August 13, 2019, 10:07am UTC](https://forums.balena.io/t/balena-supervisor-avahi/23956/11 "2019-08-13T10:07:46Z")

</div>

Thanks very much for this I will definitely give it a try!
