首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何连接运行在WSL2中的Grafana和Prometheus容器

如何连接运行在WSL2中的Grafana和Prometheus容器
EN

Stack Overflow用户
提问于 2022-03-15 18:08:31
回答 1查看 324关注 0票数 0

我在WSL2中将Prometheus和Grafana作为容器运行,我无法从Windows连接它们。我正在接收错误connect ECONNREFUSED 127.0.0.1:9090 (连接被拒绝)。

当我从WSL2内部访问它们时,一切都正常。

docker-compose.yaml

代码语言:javascript
复制
version: '3.5'

services:
  prometheus:

    image: prom/prometheus:latest
    container_name: prometheus
    volumes:
      - ./prometheus/:/etc/prometheus/
      - prometheus_data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yaml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/etc/prometheus/console_libraries'
      - '--web.console.templates=/etc/prometheus/consoles'
    network_mode: "host"

  grafana:
    image: grafana/grafana:latest
    volumes:
      - grafana_data:/data
    network_mode: "host"

volumes:
  prometheus_data:
  grafana_data:

./prometheus/prometheus.yaml

代码语言:javascript
复制
global:
alerting:
rule_files:
scrape_configs:
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-15 18:08:31

看起来,当运行在WSL2中的服务器运行在:::地址上时会出现问题,比如Grafana - http.server address=[::]:3000的默认地址。

如果主机名更改为127.0.0.1,则一切正常。

将服务器IP地址从Grafana和Prometheus更改为127.0.0.1

在Prometheus上,有必要添加此命令--web.listen-address=127.0.0.1:9090

在Grafana上,有必要添加这个环境变量GF_SERVER_HTTP_ADDR: "127.0.0.1"

docker-compose.yaml,主机名设置为127.0.0.1

代码语言:javascript
复制
version: '3.5'

services:
  prometheus:

    image: prom/prometheus:latest
    container_name: prometheus
    volumes:
      - ./prometheus/:/etc/prometheus/
      - prometheus_data:/prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yaml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/etc/prometheus/console_libraries'
      - '--web.console.templates=/etc/prometheus/consoles'
      - '--web.listen-address=127.0.0.1:9090'
    network_mode: "host"

  grafana:
    image: grafana/grafana:latest
    volumes:
      - grafana_data:/data
    environment:
      GF_SERVER_HTTP_ADDR: "127.0.0.1"
    network_mode: "host"

volumes:
  prometheus_data:
  grafana_data:
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71487030

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档