3

I have a docker container, and also installed on the VM a daemon listening for UDP on port 8125. The container sends data with UDP protocol on this 8125 port.

I was trying to open the port by starting the container with the -p 8125:8125/udp, but I'm getting the following error:

Error starting userland proxy: listen udp 0.0.0.0:8125: bind: address already in use

Which makes sense because the daemon is already listening on this port.

So how can I configure Docker so that the container can send UDP payloads to the external daemon ?

2
  • 2
    With the usual setup, the container is not limited in what it can send out (as a client). You only need to open server ports. You should be able to send UDP packets to the host (using the host IP as seen by the container, not "localhost", which would be sending to the container itself, stackoverflow.com/questions/22944631/…).
    – Thilo
    Commented May 14, 2017 at 7:53
  • Allright, so I was looking for issues on the host machine while in fact the problem was coming from inside the container :) Thanks for clarifying that
    – Overdrivr
    Commented May 14, 2017 at 8:44

1 Answer 1

10

Opening ports is only needed when you want to Listen for the requests not sending. By default Docker provides the necessary network namespace for your container to communicate to the host or outside world.

So, you could it in two ways:

  1. use --net host in your docker run and send requests to localhost:8125 in this case you containerized app is effectively sharing the host's network stack. So localhost points to the daemon that's already running in your host.

  2. talk to the container network gateway (which is usually 172.17.0.1) or your host's hostname from your container. Then your are able to send packets to your daemon in your host.

2
  • 1
    I have a question with an ongoing bounty that can be answered exactly by this (I used your second option by calling the gateway adress). It's not a duplicate because it is much higher level, etc, but the solution is the one you provided Boynux. If you want the rep, here is the link : stackoverflow.com/questions/43822074/…
    – Overdrivr
    Commented May 14, 2017 at 9:25
  • 2
    That --net host should be mentioned more often. Not many people seem to know about it. If you don't need port mapping and are fine with docker sharing the real localhost, that flag is much easier than setting up a whole virtual network for the container (and having to deal with each container having their own localhost).
    – Thilo
    Commented May 15, 2017 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.