title: How do I advertise AND browse mDNS from within docker container?
body: <p>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).</p>
  
  <p>I want to be able to run this docker container on a macOS host (during my development) AND a Linux (Debian) host for production.</p>
  
  <p><a href="https://github.com/ianblenke/docker-avahi" rel="noreferrer">https://github.com/ianblenke/docker-avahi</a> 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.</p>
  
  <p><strong>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?</strong></p>
  
  <p>Here is what I have so far.</p>
  
  <p><strong>Dockerfile</strong></p>
  
  <pre><code>FROM ubuntu:17.04    
  WORKDIR /app
  
  RUN apt-get update &amp;&amp; apt-get install -yq avahi-daemon avahi-utils libnss-mdns \
    &amp;&amp; apt-get -qq -y autoclean \
    &amp;&amp; apt-get -qq -y autoremove \
    &amp;&amp; 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"]
  </code></pre>
  
  <p><strong>start.sh</strong></p>
  
  <pre><code>#!/bin/bash
  
  service avahi-daemon restart
  service avahi-daemon status
  avahi-browse -a
  </code></pre>
  
  <p><strong>nsswitch.conf</strong></p>
  
  <p><code>hosts: files mdns_minimal [NOTFOUND=return] dns</code></p>
  
  <p><strong>avahi-daemon.conf</strong></p>
  
  <pre><code>...
  enable-dbus=no
  ...
  </code></pre>
  
  <p><strong>Running</strong></p>
  
  <pre><code>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
  </code></pre>
  
  <p>As you can see avahi-daemon is running, but <code>avahi-browse</code> doesn't think it is. Is this because I disabled dbus?</p>
  
  <p>Running the same commands (except I keep <code>enable-dbus=yes</code>)  inside a 17.04 virtualbox image on my mac things work just fine.</p>
  
  <p><strong>Update:</strong> it looks like you can <a href="https://docs.docker.com/docker-for-mac/networking/#known-limitations-use-cases-and-workarounds" rel="noreferrer">not do bridged networking on a macOS</a> host.  So is what I am trying to do impossible?</p>