从Docker容器发送udp广播 [英] sending udp broadcast from a docker container
问题描述
我有几个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?
PS
如果应用程序部署在docker(本地网络的一部分)之外,则广播工作>
broadcast works if the application is deployed outside of docker (part of the local network
推荐答案
您应该运行 docker-compose.yml
文件中定义的服务使用 network_mode:主机
。
You should either run the service defined in your docker-compose.yml
file with network_mode: host
.
或者,您可以通过发布要与之通信的容器的端口来发布它使用以下配置。请注意,<< c $ c> / 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屋!