balena-mdns-publisher configuration

My balena device is advertised under hostname.local, as expected. Now I would like it to be published also under different names (for a reverse proxy) and am trying to use balena-mdns-publisher for this purpose.

I’m using the sample configuration (below) with a few additional subdomains listed. However, none appears on my network (except hostname.local). I’m trying on an Intel NUC, for now.

Any idea what’s wrong or how I should configure the service?

balena-mdns-publisher:
    image: 'balena/balena-mdns-publisher:master'
    # build: .
    network_mode: host
    cap_add:
        - SYS_RESOURCE
        - SYS_ADMIN
    security_opt:
        - 'apparmor:unconfined'
    tmpfs:
        - /run
        - /sys/fs/cgroup
    labels:
        io.balena.features.dbus: '1'
    environment:
        CONFD_BACKEND: ENV
        MDNS_TLD: my.bob.local
        MDNS_SUBDOMAINS: >-
            ["admin", "api", "iot", "abc.local", "xyz"]
        # MDNS_API_TOKEN: 1234567890abcdef
        DBUS_SESSION_BUS_ADDRESS: 'unix:path=/host/run/dbus/system_bus_socket'

Answering my own question: I gave up on balena-mdns-publisher and instead built my own docker for the purpose.

Dockerfile:

FROM python:3.10-slim-bullseye as builder

RUN apt-get update --yes \
 && apt-get install --yes --no-install-recommends \
    build-essential \
    dbus \
    libdbus-glib-1-dev \
 && apt-get clean && rm -rf /var/lib/apt/lists/*

RUN pip install --default-timeout=1000 \
    dbus-python \
    mdns-publisher

FROM python:3.10-slim-bullseye

COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin

RUN apt-get update --yes \
 && apt-get install --yes --no-install-recommends \
    dbus \
    libdbus-glib-1-dev \
 && apt-get clean && rm -rf /var/lib/apt/lists/*

COPY app.py /

CMD [ "python", "/app.py" ]

app.py:

#!/usr/bin/env python
import os
from xml import dom

domain = os.getenv('MDNS_DOMAIN')
subdomains = os.getenv('MDNS_SUBDOMAINS').split(',')

mdns_names = [ "mdns-publish-cname", f"{domain}.local" ]
mdns_names.extend([ f"{s.strip()}.{domain}.local" for s in subdomains ])

os.execv('/usr/local/bin/mdns-publish-cname', mdns_names) 

compose:

mdns-publisher:
    build: .
    restart: unless-stopped
    labels:
        io.balena.features.dbus: 1
    environment:
        - DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket
        - MDNS_DOMAIN=my_domain
        - MDNS_SUBDOMAINS=a, xyz

This will advertise my_domain.local, a.my_domain.local, xyz.my_domain.local. You can add as many subdomains as you wish.

Alternatively you can download image ttmetro/mdns-publisher from DockerHub (amd64 and arm64).

1 Like

Hi!

We had a similar challenge and created a dockerfile for it.
You can simply embed this into your docker-compose.yml

  avahi-alias-balena:
    image: nobleo/avahi-alias-balena
    privileged: true
    network_mode: host
    environment:
      - DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket
      - CNAMES="superduperhostname.local my-address.local"
    labels:
      io.balena.features.dbus: '1'
1 Like

Hello @Timple this is amazing! This is like a balena Block. Would you like to publish it on balenaHub to enable other developers from the community with this project?

BTW in case you don’t know what are the balenaBlocks find here more information → Introducing balenaBlocks: jumpstart your IoT app development and here → Blocks: new management functionality and a public roadmap for what's next

Let us know if you need any help :slight_smile:

@ttmetro good job to enable multiple subdomains! Would you like to publish your solution on balenaHub to help other developers from the community?

Let us know if we can help you more!

In Mexico right now with poor internet. I’ll work on this when I get back- next year:)

Thanks,
Bernhard