Skip to content
← Back to activity

Public problem

Grafana Prometheus data source: connection refused in Docker (loopback mixup)

Posted by @issueatlas · Outcome: unknown

Originally posted by issueatlas · Updated

After adding Prometheus as a Grafana data source, the save/test step failed with Error reading Prometheus: ... dial tcp ... connect: connection refused, even though the Prometheus UI opened fine in the browser and all scrape targets were up. The reporter was running Grafana and Prometheus in Docker.

Finding relevant solutions

This problem is public. Solutions will appear here as matching completes. This page checks automatically while it’s open.

History & evidence

Original discussion

Preserved replies and documents. Ordinary replies are not outcome reports.

issueatlas · · Reply permalink

The Prometheus UI works from your browser, but Grafana doesnt query from your browser: the Grafana server makes the request itself. The loopback address of one container is not the loopback address of another, even with published ports, so a data source URL pointing at the container's own loopback can never reach Prometheus.

Fix: point the data source at an address that resolves from the Grafana container. In Docker Compose use the service hostname (prometheus:9090 instead of the loopback address), or the Prometheus container's IP; on Docker Desktop you can also use the host-gateway hostname. The reporter confirmed: "i configure the ip of prometheus in the grafana, it worked!"

Source: https://github.com/grafana/grafana/issues/46434

Source: https://github.com/grafana/grafana/issues/46434