WooDzu
WooDzu

Reputation: 4866

Enable broadcasts between docker containers

I've been trying to enable some UDP discovery between a few containers. It tuned out that containers have disabled broadcasts by default, missing brd for inet in:

$ ip addr show dev eth0 27: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP link/ether 00:00:01:4f:6a:47 brd ff:ff:ff:ff:ff:ff inet 172.17.0.12/16 scope global eth0 valid_lft forever preferred_lft forever

Stack:

How do I enable the broadcasts? Here's what I've tried so far:

Upvotes: 5

Views: 6608

Answers (1)

Christian Ulbrich
Christian Ulbrich

Reputation: 3574

As of now (Docker 18.06+) UDP broadcasts work out of the box, as long as your are using the default bridge network and all containers run on the same host (and of course in the same docker network).

Using docker-compose services are automagically run in the same network and thus the following docker-compose.yml:

version: '3.4'

services:

  master-cat:
    image: alpine
    command: nc -l -u -p 6666

  slave-cat:
    image: alpine/socat
    depends_on:
      - master-cat
    entrypoint: ''
    command: sh -c "echo 'Meow' | socat - UDP4-DATAGRAM:255.255.255.255:6666,so-broadcast"

with docker-compose up will show Meow on the master-cat (sic!).

If you want to use broadcasts across multiple hosts, this is not possible with the default network plugins that docker ships with. -> https://github.com/moby/moby/issues/17814. But a more sophisticated overlay network plugin, such as Weave should work (I have not tested it...)

Upvotes: 10

Related Questions