mDNS to/from a Docker container
The problem of dockerising mDNS services (e.g. Avahi etc.) is that service should be aware of its public IP address in order to advertise it. As far as I'm aware the only way to address this problem is to assign public IP to the container (which is a little bit tricky due to lack of support for static IP assignment in Docker).
This article describes technique how it can be done on Debian:
Docker service should be started with
DOCKER_OPTS="--bridge=br0 --ip-masq=false --iptables=false"
. I assume thatbr0
bridge is already configured.Container should be started with
--cap-add=NET_ADMIN --net=bridge
Inside container
pre-up ip addr flush dev eth0
in/etc/network/interfaces
can be used to dismiss IP address assigned by Docker as in following example:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
pre-up ip addr flush dev eth0
address 192.168.0.249
netmask 255.255.255.0
gateway 192.168.0.1
- Container's entry script should begin with
/etc/init.d/networking start
. Also entry script needs to edit or populate/etc/hosts
file in order to remove references to Docker-assigned IP.
Related videos on Youtube
Naftuli Kay
Updated on September 18, 2022Comments
-
Naftuli Kay almost 2 years
I've made a Docker container which runs a
forked-daapd
(a DAAP server publishing over mDNS with a single port 3689 for HTTP requests) and exposes the port properly to the host operating system:sudo docker run -it --rm -v /home/naftuli/Music:/srv/music -p 3689:3689 \ daapd /sbin/my_init
The problem is that this service never gets published properly to mDNS because its IP address (some internal Docker IP range) doesn't really work. I could run it with
--net=host
, but that's potentially pretty dangerous as I'm basically handing my network adapter to the container.Is there a way for me to publish this service and have mapping work as planned?