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 ?

Overdrivr
  • 6,296
  • 5
  • 44
  • 70
  • 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, http://stackoverflow.com/questions/22944631/how-to-get-the-ip-address-of-the-docker-host-from-inside-a-docker-container?rq=1). – Thilo May 14 '17 at 07: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 May 14 '17 at 08:44

1 Answers1

9

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.

Boynux
  • 5,958
  • 2
  • 21
  • 29
  • 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 : http://stackoverflow.com/questions/43822074/telegraf-daemon-not-receiving-metrics-from-app-deployed-with-dokku – Overdrivr May 14 '17 at 09: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 May 15 '17 at 00:43