Docker Container: UDP Communication with other hosts

Question:

i am writing a python application that is sending continously UDP messages to a predefined network with other hosts and fixed IPs. I wrote the python application and dockerized it. The application works fine in the docker, no problems there.

Unfortunately i am failing to send the UDP messages from my docker to the host so they will be sent to the other hosts in the network. The same is for receiving messages. Right now i dont know how to set up my docker so it is receiving a UDP message from a host with fixed IP adress in the network.

I tried to set up my docker network with --net host and i sent all the UDP messages from my docker container via localhost to my host. This worked fine, too. I am missing the link where i can sent the messages no to the “outside world”. I tried to make a picture of my problem.

Docker host communication problem

My Question: How do i have to set up the network communcation for my docker/host so it can receive messages via UDP from other hosts in the network?
Thanks

Asked By: bumbumquietsch

||

Answers:

Build your own bridge

1.Configure the new bridge.

$ sudo ip link set dev br0 up

$ sudo ip addr add 192.168.5.1/24 dev bridge0

$ sudo ip link set dev bridge0 up

Confirm the new bridge’s settings.

$ ip addr show bridge0

4: bridge0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state UP group default
    link/ether 66:38:d0:0d:76:18 brd ff:ff:ff:ff:ff:ff
    inet 192.168.5.1/24 scope global bridge0
       valid_lft forever preferred_lft forever <br/>       

2. Configure Docker to use the new bridge by setting the option in the daemon.json file, which is located in /etc/docker/ on Linux or C:ProgramDatadockerconfig on Windows Server. On Docker for Mac or Docker for Windows, click the Docker icon, choose Preferences, and go to Daemon.

If the daemon.json file does not exist, create it. Assuming there are no other settings in the file, it should have the following contents:

{
  "bridge": "bridge0"
}

Restart Docker for the changes to take effect.

3. Confirm that the new outgoing NAT masquerade is set up.

    $ sudo iptables -t nat -L -n

    Chain POSTROUTING (policy ACCEPT)
    target     prot opt source               destination
    MASQUERADE  all  --  192.168.5.0/24      0.0.0.0/0

4.Remove the now-unused docker0 bridge.

$ sudo ip link set dev docker0 down

$ sudo ip link del name br0

$ sudo iptables -t nat -F POSTROUTING

5.Create a new container, and verify that it is in the new IP address range.

(ref.)

Answered By: Mayur

So i experimented a lot and i figured out, that i just need to run the docker container with the network configuration as host. The UDP socket in my container is bound to the IP adress of my host and therefore just needs to be linked to the Network of the host. Everyone who is struggeling the same issue, just run

docker run --network=host <YOURCONTAINER>
Answered By: bumbumquietsch

enter image description here

Now I want to ask you that How you had done UDP from Docker to local host. Now I have Rpi Border Router in that I am using Wi-sun Docker. So it get connect to wi-sun node. Now in that I want to do UDP communication between Border Router and Wi-sun Node. So what I have to add in docker side for UDP. AS I want all message in wsbrd only i.e log.

Docker used:https://github.com/SiliconLabs/wisun-br-linux-docker

@bumbumquietsch please help me with these. How you had done your first step mention in snapshort

Answered By: Harsh Dani
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.