Prometheus中Docker监控目标localhost:9323状态Down,求解决方案
解决Prometheus监控Docker指标目标Down的问题
问题根源
Prometheus容器内的localhost指向容器自身,而Docker daemon的metrics服务运行在宿主机上,因此容器内访问localhost:9323会出现连接拒绝。
解决方案(二选一即可)
方案1:修改Prometheus采集目标地址
- 编辑
prometheus.yml,将Docker采集任务的targets替换为宿主机IP或Docker内置的宿主机别名(host.docker.internal,适用于Docker Desktop):
# my global config global: scrape_interval: 15s evaluation_interval: 15s external_labels: monitor: 'codelab-monitor' scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] - job_name: 'docker' static_configs: # 替换为你的宿主机实际IP,例如192.168.3.10:9323,或使用host.docker.internal - targets: ['host.docker.internal:9323']
- 重启Prometheus容器使配置生效:
docker restart prometheus
方案2:让Prometheus容器使用宿主机网络
启动Prometheus时添加--network host参数,让容器直接使用宿主机网络栈,此时容器内的localhost将指向宿主机:
docker run -d --name prometheus \ --network host \ -v ./prometheus.yml:/etc/prometheus/prometheus.yml \ prom/prometheus
注意:使用宿主机网络后无需再映射
-p 9090:9090,直接访问宿主机的9090端口即可打开Prometheus界面。
前置验证步骤
在调整配置前,先确认Docker metrics服务正常运行:
- 确保已重启Docker服务使
daemon.json的配置生效:
# Linux系统 sudo systemctl restart docker # Docker Desktop(Windows/Mac)直接在界面点击重启
- 在宿主机执行以下命令,验证metrics服务可访问:
curl http://localhost:9323/metrics
若能返回大量指标数据,说明Docker metrics服务正常。
内容的提问来源于stack exchange,提问作者mhassaankhokhar
相关产品推荐
相关产品推荐

