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

I’m having issues getting data sent into a statsd container. I can successfully send data while on the command line inside the container itself. I need to be able to send statistic data to it from the host machine or from another Docker container.

I’m using Kitematic, I can see that the selection for ‘bridge’ network is checked on both containers. Using a bridge network was a suggestion I found for this issue.

I also tried passing ‘-P’ to Docker while running the command to build the container, as that was supposed to expose the ports. I didn’t notice a difference in the way it behaved when sending data from the other container.

Example of code that runs to create fake statistics using port 8125 on localhost (taken from this Docker container webpage 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

The container is created using the following command:

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

I’ve tried making sure both are on the same ‘bridge’ network. I’m running Docker Desktop on Windows 10 Enterprise. I’ve found several commands dealing with iptables and networking on Linux, but I feel like I’m missing something. I might also mention that statsd uses UDP connection on port 8125 by default.

If I try running the example command from another container on the bridge network, I don’t get any result. I know the data (from another container) is not getting over correctly because I can’t see it in the metrics that get received on the statsd dashboard.

I can ping localhost:8125 and get a response from within another container. From the outside (Powershell window on the host machine) it won’t resolve.

 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>

Source: StackOverflow