21

I'm trying to create a ubuntu 17.04 based docker container that can browse mDNS on my network (outside of the docker network) AND advertise on mDNS to my network (outside of docker network).

I want to be able to run this docker container on a macOS host (during my development) AND a Linux (Debian) host for production.

https://github.com/ianblenke/docker-avahi seems to have solved this for Linux hosts (utilizing avahi daemon and mapping the /var/run/dbus volume to the host). When I'm developing on my macbook, I would like to use mDNSResponder.

How do I create a container that can advertise and browse on my local network, that will also run on my macOS laptop and on a Linux server?

Here is what I have so far.

Dockerfile

FROM ubuntu:17.04    
WORKDIR /app

RUN apt-get update && apt-get install -yq avahi-daemon avahi-utils libnss-mdns \
  && apt-get -qq -y autoclean \
  && apt-get -qq -y autoremove \
  && apt-get -qq -y clean

RUN update-rc.d avahi-daemon enable

COPY docker/etc/nsswitch.conf /etc/nsswitch.conf
COPY docker/etc/avahi-daemon.conf /etc/avahi/avahi-daemon.conf

COPY docker/start.sh /app    

CMD ["/bin/bash","start.sh"]

start.sh

#!/bin/bash

service avahi-daemon restart
service avahi-daemon status
avahi-browse -a

nsswitch.conf

hosts: files mdns_minimal [NOTFOUND=return] dns

avahi-daemon.conf

...
enable-dbus=no
...

Running

docker run --net=host -it mdns1
 * Restarting Avahi mDNS/DNS-SD Daemon avahi-daemon                      [ OK ]
Avahi mDNS/DNS-SD Daemon is running
Failed to create client object: Daemon not running

As you can see avahi-daemon is running, but avahi-browse doesn't think it is. Is this because I disabled dbus?

Running the same commands (except I keep enable-dbus=yes) inside a 17.04 virtualbox image on my mac things work just fine.

Update: it looks like you can not do bridged networking on a macOS host. So is what I am trying to do impossible?

rynop
  • 50,086
  • 26
  • 101
  • 112
  • 1
    Isn't the `--net=host` option enough? With that the container has access to the host interface. – Robert May 20 '17 at 02:30
  • 1
    Nope. Linux (os I'm running in the container) requires avahi-daemon, which AFAIK requires dbus. https://github.com/ianblenke/docker-avahi is a docker image that works if your host is linux. Does not if your host is macOS (as it does not use dbus). Or is this an incorrect assertion? – rynop May 23 '17 at 21:39
  • 1
    FYI I was not able to get the ianblenke image to work in linux, and it seems several other people tried and failed as well. – John Wiseman Apr 04 '19 at 06:18
  • Seems like there is still not a solution for this... – Biaspoint Jan 17 '23 at 20:55

2 Answers2

0

I'm currently trying to get avahi working inside a docker container and in my research came across this:

you can in the Avahi settings configuration disable dbus so it won't use it. Then when you run Avahi in Docker you must pass it the --no-rlimits flag and it'll work without compromising your containers security.

https://www.reddit.com/r/docker/comments/54ufz2/is_there_any_way_to_run_avahi_in_docker_without/

Hopefully this can help with your situation.

Michal
  • 9
  • 2
  • Yup I've tried this, option is `enable-dbus=no`. Still does not work. I'm on macOS host. I don't get why he says you MUST use `--no-rlimits`. Do you know? Seems like that would cause issues. – rynop May 25 '17 at 20:05
-2

For mdns advertising/listening we run dnssd inside docker containers.

But! In order to be discoverable on a local network the docker container should have an IP address from the network, proper routes from the network to docker container should be configured.

If you do not have control over the default router of the network, you can try to use macvlan/ipvlan network driver. It will allows you to assign multiple mac/IP addresses on the same network interface.

In our case, the network is wifi, so we had to use the ipvlan, because macvlan does not works with wifi. In a wired case you should prefer macvlan.

kerzol
  • 325
  • 2
  • 14
  • 2
    can you add an example network configuration for a docker-compose file for a starting point? – Andy P Aug 01 '21 at 21:52