默认情况下,docker容器是否可以调用主机的localhost UDP? [英] By default, can a docker container call host's localhost UDP?
问题描述
我试图通过启动容器的 -p 8125:8125 / udp
打开端口,但是我收到以下错误:
启动userland代理时出错:listen udp 0.0.0.0:8125:bind:地址已在使用
pre>
这是有道理的,因为守护进程已经在这个端口上侦听。
那么如何配置Docker,以便容器可以将UDP有效内容发送到外部守护程序?
解决方案只有当您想收听不发送请求时,才需要打开端口。默认情况下,Docker为您的容器提供必要的网络命名空间,以便与主机或外部世界进行通信。
所以,您可以通过两种方式:
在您的
docker运行中使用
并发送请求到- net host
localhost:8125
在这种情况下,您集装箱化的应用程序有效地共享主机的网络堆栈。所以本地主机指向您的主机中已经运行的守护程序。
与容器网关(通常是$ code> 172.17.0.1 )或您的主机的主机名。然后你可以发送数据包到您的主机中的守护进程。
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.
这篇关于默认情况下,docker容器是否可以调用主机的localhost UDP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!