1
votes

I am trying to setup a grafana,influxdb,telegraf container but I can't seem to come right. I get a Network Error: Bad Gateway(502) error when I try to create the data source.

The data source is updated but the network test fails

Here is my yml conf:

version: "3"
services:
  grafana:
    image: grafana/grafana
    container_name: grafana
    restart: always
    ports:
      - 3000:3000
    networks:
      - monitoring
    volumes:
      - grafana-volume:/var/lib/grafana
  influxdb:
    image: influxdb
    container_name: influxdb
    restart: always
    ports:
      - 8086:8086
   networks:
      - monitoring
    volumes:
      - influxdb-volume:/var/lib/influxdb
networks:
  monitoring:
volumes:
  grafana-volume:
    external: false
  influxdb-volume:
    external: false

For now, I hashed out network configs because I was trying to see if it made any difference if I let docker create the network.

I am using a MacBook and my docker version is :

Docker version 19.03.5, build 633a0ea

When checking logs I do see tcp being blocked on my localhost machine port 8086 but I have no proxy/firewall enforced. Heres a bit of the log results

t=2020-02-12T10:42:25+0000 lvl=info msg="Initializing Stream Manager"
t=2020-02-12T10:42:25+0000 lvl=info msg="HTTP Server Listen" logger=http.server address=[::]:3000 protocol=http subUrl= socket=
t=2020-02-12T10:43:54+0000 lvl=eror msg="Failed to look up user based on cookie" logger=context error="user token not found"
t=2020-02-12T10:43:54+0000 lvl=info msg="Request Completed" logger=context userId=0 orgId=0 uname= method=GET path=/ status=302 remote_addr=192.168.96.1 time_ms=10 size=29 referer=
t=2020-02-12T10:44:00+0000 lvl=info msg="Successful Login" logger=http.server User=admin@localhost
t=2020-02-12T10:45:35+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=192.168.96.1 time_ms=43 size=0 referer=http://0.0.0.0:3000/datasources/edit/1/?gettingstarted
2020/02/12 10:45:35 http: proxy error: dial tcp 127.0.0.1:8086: connect: connection refused

Port 8086 is up and listening

tcp46      0      0  *.8086                 *.*                    LISTEN
2

2 Answers

3
votes

Datasource server value 127.0.0.1:8086 is not valid in the container (localhost in the container != OS localhost - container lives in the different network namespace usually).

Grafana container in your case is in monitoring network, so connect to influxdb:8086, instead of 127.0.0.1:8086.

0
votes

what is happining is grafana is searching influxdb on his localmachine(container), so here you need to link grafana with influxdb, add this in grafana:

    links:
     - influxdb