启用Docker容器之间的广播 [英] Enable broadcasts between docker containers

查看:248
本文介绍了启用Docker容器之间的广播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在几个容器之间启用一些UDP发现。
它调出容器默认情况下已禁用广播,缺少inet的brd:

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:<广播,多播,UP,LOWER_UP> mtu 1500 qdisc noqueue状态UP
link / ether 00:00:01:4f:6a:47 brd ff:ff:ff:ff:ff:ff:ff
inet 172.17.0.12/16作用域全局eth0
valid_lft永远preferred_lft永远

堆栈:


  • 主机:ubuntu 14.04

  • 容器:ubuntu 12.04

  • docker 1.8.3

如何启用广播?到目前为止,这是我尝试过的操作:

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


  • ip链接集dev eth0广播172.17.255.255 提供 RTNETLINK答案:无效参数

  • 与--privileged容器相同

  • 与NET_ADMIN和NET_BROADCAST容器功能相同

  • ip link set dev eth0 broadcast 172.17.255.255 gives RTNETLINK answers: Invalid argument
  • same with --privileged container
  • same with NET_ADMIN and NET_BROADCAST container capabilities

推荐答案

到目前为止(Docker 18.06+)UDP广播只要您使用默认的桥接网络 ,并且所有容器都在相同主机上运行(当然,并且在同一docker网络中),即可直接使用。

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

使用docker-compose服务自动在同一网络中运行,因此以下 docker-compose.yml

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 将在主猫上显示 Meow (原文如此!)。

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

如果想要跨多个主机使用广播,这对于Docker随附的默认网络插件是不可能的。-> https://github.com/moby/moby/issues/17814 。但是有一个更复杂的覆盖网络插件,例如编织 应该可以正常工作(我尚未对其进行测试...)

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

这篇关于启用Docker容器之间的广播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆