Search code examples
networkingdocker-composezeroconf

Zeroconf discovery from docker-compose container to LAN host


For an IoT system there is the requirement that base stations automatically discover nearby devices, and then connect to them. The software on the base stations is deployed using docker-compose.

Services advertise using mDNS (zeroconf), and identify themselves as being of the type mytype. Clients use aiozeroconf to discover services matching _mytype._tcp.local..

The problem is that clients inside a docker-compose network don't discover services in the LAN network - even if they are otherwise reachable.

Currently, I have the following setup:

LAN (Wifi)
  - IoT device
    - ServiceA
  - Host / base station
    - ClientA
    - Docker-compose network
      - ServiceB
      - ClientB
  • ClientA finds both ServiceA and ServiceB
  • ClientB finds ServiceB
  • avahi-discover on Host finds both ServiceA and ServiceB
  • ClientB can connect to ServiceA using the LAN IP (192.168.x.x)

Is this scenario considered out-of-spec for mDNS (ServiceA no longer considered in .local), or can this be solved?


Solution

  • You can use mdns-repeater to forward mDNS packets from the host network to the Docker network and enable the containers to discover devices in your LAN.