sending udp broadcast from a docker container
Asked Answered
F

3

19

I'm having a few docker containers (Using docker-compose and a single network - 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

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?

P.S

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

Ferment answered 24/5, 2018 at 11:58 Comment(1)
I think this will only work when running on network_mode: host. But I am no networking expert to confirm thatEdaphic
P
7

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

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"
Polypeptide answered 30/5, 2018 at 10:43 Comment(1)
For some reason, It didn't work for me. Anyhow I'm upvoting because it seems like the logic answerFerment
I
0

I have gotten some luck out of this. The guide specifies sysctl parameters that are needed for broadcast forwarding from a docker network, you should then be able to either use his script or specify these parameters when running docker.

Internuncial answered 27/10, 2020 at 1:38 Comment(0)
R
0
  • use docker compose file
  • use bridge network
version: '3'
services:
  idhub-go:
    container_name: test
    image: 'nginx'
    ports:
      - "2641:2641/tcp"
      - "2641:2641/udp"
Roebuck answered 9/6, 2023 at 6:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.