容器化Grafana无法连接容器化Prometheus

问题描述 投票:0回答:1

尝试将 Prometheus 连接到 Grafana 时出现以下错误。

发布“http://localhost:9090/api/v1/query”:拨打 tcp 127.0.0.1:9090:连接:连接被拒绝 - 查询 Prometheus API 时返回错误。

当我尝试在本地执行此操作时,我没有收到相同的错误。

我不确定发生了什么,因为这在本地层面有效。

docker prometheus grafana
1个回答
4
投票

这是因为容器内的“localhost”只是该特定容器内的内容(grafana 容器中仅运行 grafana)。

在这种情况下,您需要使用 prometheus 容器的名称而不是 localhost,即“http://prometheus:9090”,并确保两个容器位于同一 docker 网络上。

Docker 可以在 docker 网络内将容器名称解析为主机名。

© www.soinside.com 2019 - 2024. All rights reserved.