简体   繁体   English

Docker 带有两个 InfluxDB 的 Grafana:连接被拒绝

[英]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.我创建了一个新的 docker-stack,我需要几个 influxdb 实例,我无法连接到我的 grafana 容器 atm。 Here is a port of my docker-compose.yml这是我的 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:当我尝试使用 influxdb-2 在 grafana 中创建新的 influxdb 数据源时,出现网络错误:错误网关(502),日志文件显示:

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. @hmm 提供了答案。

When you create services within Docker Compose, you:在 Docker Compose 中创建服务时,您:

  • are able to access containers by the service name.能够通过服务名称访问容器。 Grafana will reference influxdb-2 by that name. Grafana 将使用该名称引用influxdb-2
  • 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;根据@hmm,仍然必须在端口8086上引用influxdb-2 ,因为这是容器公开的端口; 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]]您可以(但您不需要)将容器的端口公开给主机(使用--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 .总而言之,应该将influxdb-2中的 InfluxDB 服务引用为influxdb-2:8086 If you want to expose this service to the host (,), you could do ports: - 12380:8086 .如果你想将此服务公开给主机(,),你可以做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 ).您可以将12380的值更改为主机上可用的值,但不能更改容器端口 ( 8086 ) 的值。

The main reason that you would include the --ports: flag on influxdb-2 is for debugging from the host.influxdb-2上包含--ports:标志的主要原因是为了从主机进行调试。 But the grafana service does not require this.但是grafana服务不需要这个。 It will access the influxdb-2 service through the network provisioned by Docker Compose on port 8086 .它将通过 Docker Compose 在端口8086上提供的网络访问influxdb-2服务。

You do want to expose the grafana service on the host because, otherwise, it would be inaccessible to you (from the host).确实希望在主机上公开grafana服务,否则,您(从主机)将无法访问它。 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. grafana是主机公共的,但influxdb*服务可能是主机私有的,因为它们通常只被grafana服务需要。

HTH!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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