我正在尝试配置prometheus和grafana来监控我的django应用程序,但是当执行docker-compose up命令时抛出这个错误:
grafana_prometheus_ctnr | level=error ts=2020-10-20T13:08:42.474Z caller=main.go:290 msg="Error loading config (--config.file=/etc/prometheus/prometheus.yml)" err="open /etc/prometheus/prometheus.yml: no such file or directory"我有各种各样的服务,其中之一是普罗米修斯。
docker-compose.yml:
...
prometheus:
container_name: grafana_prometheus_ctnr
build:
context: .
dockerfile: Dockerfile-prometheus
volumes:
- ./prometheus-data:/etc/prometheus
ports:
- 9090:9090
networks:
- grafana-ntwk
...Dockerfile-prometheus:
FROM prom/prometheus:v2.22.0
LABEL version="1.0.0"
COPY ./prometheus.yml /etc/prometheus/
COPY ./prometheus.json /etc/prometheus/file_sd/
EXPOSE 9090prometheus.yml:
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_timeout: 10s
scrape_configs:
- file_sd_configs:
files:
- /etc/prometheus/file_sd/*.jsonprometheus.json:
[
{
"targets": ["0.0.0.0:9090"],
"labels": {
"job": "prometheus",
"environment": "develope",
}
},
{
"targets": ["0.0.0.0:8000"],
"labels": {
"job": "django",
"environment": "develope",
}
},
{
"targets": ["0.0.0.0:5432"],
"labels": {
"job": "postres",
"environment": "develope",
}
}
]有人知道为什么文件没有被复制吗?
发布于 2020-10-22 15:02:04
这个更新对我来说效果很好:
Dockerfile-prometheus:
...
COPY ./prometheus.yml /etc/prometheus/prometheus.yml
COPY ./prometheus.json /etc/prometheus/file_sd/prometheus.json
...docker-compose.yml:
...
prometheus:
container_name: grafana_prometheus_ctnr
build:
context: .
dockerfile: Dockerfile-prometheus
volumes:
- ./prometheus-data:/etc/prometheus
ports:
- 9090:9090
networks:
- grafana-ntwk
...prometheus.yml:
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_timeout: 10s
scrape_configs:
- job_name: 'monitoring'
file_sd_configs:
- files:
- /etc/prometheus/file_sd/*.json发布于 2020-10-22 05:46:26
问题出在您的Dockerfile和docker-compose文件中。Dockerfile将prometheus.yml复制到/etc/prometheus目录。docker-compose还将卷挂载到同一目录中。在这种情况下,容器内目录中的现有文件会被屏蔽,因为docker会将它们挂载在现有文件之上。文件仍然在容器中,但它们是不可访问的。从docker文件中删除COPY,或者从docker-compose中删除卷,或者将它们挂载到另一个目录中。
https://stackoverflow.com/questions/64446044
复制相似问题