从 docker 容器发送 udp 广播

编程入门 行业动态 更新时间:2024-10-25 00:32:58
本文介绍了从 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 广播

本文发布于:2023-10-07 13:00:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469456.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:容器   docker   udp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!