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 ?
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:
use
--net host
in yourdocker run
and send requests tolocalhost: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.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.