0
votes

Is it possible to send a message with a Socket from inside a docker container to the network of the host that deploys it? I mean...

I have a router with two hosts connected. One of them deploys a docker container with an image that uses a Socket in Python to send UDP multicast messages. The other host in the network executes a program that listens to that multicast address to receive UDP messages (but it doesn't run inside a docker container).

I am trying to run the container with the following command:

docker run --name send-udp-container -p 192.168.0.100:5007:5007/udp udp-image

What I am trying to achieve with this is to map the port 5007 of the host with the port 5007 with the container. So, when the container sends the UDP message to that port, it is broadcasted through 192.168.0.100 IP address (which is the interface I want to use to communicate with the other host).

I know it can be fixed using this command to share the network:

docker run --name send-udp-container --network host udp-image

But I would prefer to avoid sharing the network. Any Ideas?

1

1 Answers

0
votes

Untested:

# create a network and set the gateway 
docker network create -d bridge --subnet 192.168.0.0/24 --gateway 192.168.0.1 mynetwork

docker run --net=mynetwork --name send-udp-container udp-image

Now from inside the container, you should be able to reach 192.168.0.100