I am getting the following error when trying to connect Prometheus to Grafana.
Post "http://localhost:9090/api/v1/query": dial tcp 127.0.0.1:9090: connect: connection refused - There was an error returned querying the Prometheus API.
I don't get the same error when I try doing this locally.
I am not sure what is going on, because this works at a local level.
This is due to the fact that inside a container 'localhost' is only what is inside that specific container (only grafana is running in the grafana container).
In this case you will need to use the name of the prometheus container instead of localhost i.e "http://prometheus:9090" and ensure that both containers are on the same docker network.
Docker can resolve the container name as a hostname, within the docker network.