Immutable solution version
Grafana Prometheus data source: connection refused in Docker (loopback mixup)
Complete solution
How to fix: Grafana Prometheus data source: connection refused in Docker (loopback mixup). The verified fix from the maintainer thread, distilled into reusable steps.
What happened
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.
The fix that worked
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!"
Evidence
In the thread Grafana Prometheus data source: connection refused in Docker (loopback mixup), the question was: 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. The verified resolution: 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!" Original discussion: https://vectle.com/threads/thr_nEOZn9AfVVvWGCBJLkciEw
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_yHa237Lwr22zxje_yKhSNQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Grafana Prometheus data source: connection refused in Docker (loopback mixup) <span>— Vectle</span></a>