从 docker 容器发送 udp 广播 [英] sending udp broadcast from a docker container

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

问题描述

我有几个 docker 容器(使用 docker-compose 和单个网络 - network-sol)

I'm having a few docker containers (Using docker-compose and a single network - network-sol)

其中一个容器是 Spring Boot 应用程序,它将 UDP 广播发送到本地网络.255.255.255.255 失败,因为它是 network-sol

One of the containers is a Spring Boot application that sends UDP broadcast to the local network. 255.255.255.255 fails because It's the local broadcast address of network-sol

我怎样才能广播UDP消息,例如顶级本地网络"会得到那些数据包?我必须为此使用定向广播地址吗?

How can I broadcast UDP messages such as the "top local network" Will get those packets? Do i have to use directed broadcast address for that?

附言

如果应用程序部署在 docker 之外(本地网络的一部分),则广播可以工作

broadcast works if the application is deployed outside of docker (part of the local network

推荐答案

您应该使用 network_mode: host 运行 docker-compose.yml 文件中定义的服务.

You should either run the service defined in your docker-compose.yml file with network_mode: host.

或者,您可以使用以下配置发布要与之通信的容器的端口.请注意,UDP 通信需要 /udp 才能工作.

Alternatively you can publish the port of the container you intended to communicate with by publishing it using the following configuration. Note that the /udp is required for UDP communication to work.

service:
  ports:
    - "8080:8080/udp"

这篇关于从 docker 容器发送 udp 广播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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