我在WSL2中将Prometheus和Grafana作为容器运行,我无法从Windows连接它们。我正在接收错误connect ECONNREFUSED 127.0.0.1:9090 (连接被拒绝)。
当我从WSL2内部访问它们时,一切都正常。
docker-compose.yaml
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
global:
alerting:
rule_files:
scrape_configs:发布于 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
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:https://stackoverflow.com/questions/71487030
复制相似问题