Enable broadcasts between docker containers

给你一囗甜甜゛ 提交于 2019-12-06 00:08:35

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...)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!