默认情况下,docker容器是否可以调用主机的localhost UDP? [英] By default, can a docker container call host's localhost UDP?

查看:627
本文介绍了默认情况下,docker容器是否可以调用主机的localhost UDP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个docker容器,并且还在VM上安装了一个在端口8125上侦听UDP的守护进程。容器在该8125端口上发送UDP协议数据。



我试图通过启动容器的 -p 8125:8125 / udp 打开端口,但是我收到以下错误:

 启动userland代理时出错:listen udp 0.0.0.0:8125:bind:地址已在使用
pre>

这是有道理的,因为守护进程已经在这个端口上侦听。



那么如何配置Docker,以便容器可以将UDP有效内容发送到外部守护程序?

解决方案

只有当您想收听不发送请求时,才需要打开端口。默认情况下,Docker为您的容器提供必要的网络命名空间,以便与主机或外部世界进行通信。



所以,您可以通过两种方式:


  1. 在您的 docker运行中使用 - net host 并发送请求到 localhost:8125 在这种情况下,您集装箱化的应用程序有效地共享主机的网络堆栈。所以本地主机指向您的主机中已经运行的守护程序。


  2. 与容器网关(通常是$ 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:

  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.

这篇关于默认情况下,docker容器是否可以调用主机的localhost UDP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆