Cannot connect to Influx datasource from Grafana



Hello, I’ve been trying to create myself a raspberry pi temperature sensor and with some of the excellent articles out there, I’ve got to the point where it seems I am nearly complete.

I have been following this guide:

I have created my Ubuntu server VM, installed Docker and ran the following commands to get the containers created, but for some reason, I cannot get Grafana to connect to InfluxDB.

My settings are as follows:

InfluxDB details: Database: dbname user: user password: pass

Now, my Raspberry Pi is running the python script and outputting a temperature. I have configured the Pi script with the following:

  • influx_host = ‘’
  • host = ‘grafana’
  • port = 8086
  • dbname = ‘dbname’
  • user = ‘user’
  • password = ‘pass’
  • temp_sensor = ‘/sys/bus/w1/devices/28-0113136957aa/w1_slave’

Whenever I try to Save and Test the datasource, I am getting:

*Network Error: Bad Gateway (502)

I’ve done a bit of searching and can’t seem to identify why it will not connect to the InfluxDB.

When I try to save and Test, I get this output from my Docker VM:

grafana_1 | 2019/01/07 20:29:39 http: proxy error: dial tcp connect: connection refused grafana_1 | t=2019-01-07T20:29:39+0000 lvl=info msg=“Request Completed” logger=context userId=1 orgId=1 uname=admin method=GET path=/api/datasources/proxy/1/query status=502 remote_addr= time_ms=15 size=0 referer=

It seems that Influx is refusing my connection?

Does anybody know what may be wrong?

Thank you



As you are using Docker containers for your setup, you need to be aware how the networking stack works with Docker Compose.

    image: influxdb
     - "8083:8083"
     - "8086:8086"

With the above, your InfluxDB service is publishing ports to the host. This means your script can connect to InfluxDB on localhost:8086.

As Grafana runs as a container inside of the Docker networking stack, Grafana should be configured to speak to InfluxDB using the http://influx:8086 (when using “Access: Server”) or localhost when using “Access: Client”.

When using server access, you use influx as the hostname because that is what your service is called within the docker-compose.yml file.