简体   繁体   中英

Docker Grafana with two InfluxDBs: Connection refused

i created a new docker-stack where i would need several influxdb instances, which i can't connect to my grafana container atm. Here is a port of my docker-compose.yml

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

  influxdb-2:
    image: influxdb
    container_name: influxdb-2
    restart: always
    ports:
      - 12380:12380
    networks:
      - monitoring
    volumes:
      - influxdb-volume-2:/var/lib/influxdb

When i try to create a new influxdb datasource in grafana with influxdb-2 i get a Network Error: Bad Gateway(502), the logfile is showing:

2782ca98a4d7_grafana | 2019/10/05 13:18:50 http: proxy error: dial tcp 172.20.0.4:12380: connect: connection refused

Any ideas?

Thanks

@hmm provides the answer.

When you create services within Docker Compose, you:

  • are able to access containers by the service name. Grafana will reference influxdb-2 by that name.
  • are not able to change the ports a container exposes. Per @hmm, influxdb-2 must still be referenced on port 8086 because that's the port the container exposes; you can't change it unless you change the image.
  • you may (but you don't need to) expose the containers' ports to the host (using --ports: [[HOST-PORT]]:[[CONTAINER-PORT]]

Long and the short of it is that the InfluxDB service in influxdb-2 should be referenced as influxdb-2:8086 . If you want to expose this service to the host (,), you could do ports: - 12380:8086 . You may change the value of 12380 to something available on your host but you cannot change the value of the container port ( 8086 ).

The main reason that you would include the --ports: flag on influxdb-2 is for debugging from the host. But the grafana service does not require this. It will access the influxdb-2 service through the network provisioned by Docker Compose on port 8086 .

You do want to expose the grafana service on the host because, otherwise, it would be inaccessible to you (from the host). It's akin to public|private. grafana is host public but the influxdb* services may be host private because they are generally only needed by the grafana service.

HTH!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM