从外部容器向 docker 上的 statsd / graphite 数据库发送数据时出现问题

Having problems sending data to statsd / graphite database on docker from outside container

我在将数据发送到 statsd 容器时遇到问题。我可以在容器本身的命令行上成功发送数据。我需要能够从主机或另一个 Docker 容器向它发送统计数据。

我正在使用 Kitematic,我可以看到在两个容器上都选中了 'bridge' 网络的选择。使用桥接网络是我为这个问题找到的一个建议。

我还尝试将“-P”传递给 Docker,同时 运行 使用命令构建容器,因为这应该会公开端口。从另一个容器发送数据时,我没有注意到它的行为方式有何不同。

运行在本地主机上使用端口 8125 创建虚假统计信息的代码示例(取自此 Docker 容器网页 https://hub.docker.com/r/graphiteapp/graphite-statsd

Let's fake some stats with a random counter to prove things are working.

while true; do echo -n "example:$((RANDOM % 100))|c" | nc -w 1 -u     127.0.0.1 8125; done

使用以下命令创建容器:

docker run -d --name graphite --restart=always -p 80:80 -p 2003-2004:2003-2004 -p 2023-2024:2023-2024 -p 8125:8125/udp -p 8126:8126 graphiteapp/graphite-statsd

我已尝试确保两者都在同一个 'bridge' 网络上。我在 Windows 10 Enterprise 上 运行ning Docker 桌面。我在 Linux 上发现了几个处理 iptables 和网络的命令,但我觉得我遗漏了什么。我可能还会提到 statsd 默认使用端口 8125 上的 UDP 连接。

如果我尝试 运行 从桥接网络上的另一个容器中执行示例命令,我没有得到任何结果。我知道数据(来自另一个容器)没有正确传输,因为我无法在 statsd 仪表板上收到的指标中看到它。

我可以 ping localhost:8125 并从另一个容器中获得响应。从外部(主机上的 Powershell window)它无法解析。

 PING localhost:8125 (127.0.0.1): 56 data bytes
 64 bytes from 127.0.0.1: seq=0 ttl=64 time=0.024 ms
 64 bytes from 127.0.0.1: seq=1 ttl=64 time=0.052 ms
 64 bytes from 127.0.0.1: seq=2 ttl=64 time=0.031 ms
 ^C
 --- localhost:8125 ping statistics ---
 3 packets transmitted, 3 packets received, 0% packet loss
 round-trip min/avg/max = 0.024/0.035/0.052 ms>

如果我 运行 docker container ls 那么我得到以下结果:

我发现我需要获取每个容器的具体IP地址,可以通过运行docker inspect (name of network)找到。在这种情况下,bridge.

然后我需要指定容器的IP地址。我用那个 IP 地址替换了建议的地址,它起作用了。