Windows10 docker: Grafana not able to access influxdb

Hi Team,

I have installed two containers(influxdb and grafana).
Two containers up and running. Able to access grafana(http://localhost:3000/datasources/edit/1/) and influxdb(http://localhost:8086/query?q=show%20databases) urls from browser.
But when we configure influxdb in grafana, grafana api throwing 502: Bad Gateway.

Grafana log message
t=2020-12-23T23:53:36+0000 lvl=eror msg="Data proxy error" logger=data-proxy-log userId=1 orgId=1 uname=admin path=/api/datasources/proxy/1/query remote_addr=xxx.xx.x.x referer=http://localhost:3000/datasources/edit/1/ error="http: proxy error: dial tcp localhost:8086: connect: connection refused"

t=2020-12-23T23:53:36+0000 lvl=eror msg="Request Completed" logger=context userId=1 orgId=1 uname=admin method=GET path=/api/datasources/proxy/1/query status=502 remote_addr=1xxx.xx.x.x time_ms=26 size=0 referer=http://localhost:3000/datasources/edit/1/

Docker Compose file:
version: “2”
services:
grafana:
image: grafana/grafana
container_name: grafana
restart: always
ports:
- 3000:3000
volumes:
- grafana_storage:/var/lib/grafana_storage
networks:
- ranga_docker_network

influxdb:
image: influxdb
container_name: influxdb
restart: always
ports:
- 8086:8086
volumes:
- influxdb_storage:/var/lib/influxdb_storage
networks:
- ranga_docker_network
environment:
- INFLUXDB_DB=telegraf
- INFLUXDB_USER=telegraf
- INFLUXDB_ADMIN_ENABLED=true
- INFLUXDB_ADMIN_USER=admin
- INFLUXDB_ADMIN_PASSWORD=telegraf1234
networks:
ranga_docker_network:
volumes:
grafana_storage:
influxdb_storage:

Thanks,
Ranga Rao

Docker network also up and running.

C:\WINDOWS\system32>docker network ls
NETWORK ID NAME DRIVER SCOPE
f42bea59b834 bridge bridge local
5ae575311d19 host host local
d7f57802a04c monitoring_default bridge local
2419751561dd monitoring_monitoring bridge local
4829f3a73843 monitoring_ranga_docker_network bridge local
4962bd901e12 none null local
ad245f671c22 ranga_docker_network bridge local

First you need to understand that each container is running in own network net space = each container has own locahost, which is indepentend from other containers localhosts. Generally, localhost in Grafana container is not localhost in the InfluxDB container.

In your case you can still reach influxdb, just replace localhost with influxdb. Please read some docker networking doc to see more details.

Thanks Jangaraj for quick reply. Created bridge network and connected both containers to same bridge network.

Issue Root Cause: Connected VPN but didn’t restart docker daemon.
Issue Resolution: After connecting VPN, restart docker daemon.