gpt4 book ai didi

docker - Prometheus不是在vm上运行,而是在本地Docker上运行

转载 作者:行者123 更新时间:2023-12-02 20:04:03 26 4
gpt4 key购买 nike

我正在尝试让普罗米修斯在vm上运行。我有几个要监视的微服务,它们正在vm上运行。我将以下内容添加到docker-compose.yml文件之一:

prometheus:
image: prom/prometheus:v2.1.0
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
ports:
- '9090:9090'

然后将prometheus.yml文件添加到与上述docker-compose相同的文件夹中。
global:
scrape_interval: 15s
evaluation_interval: 15s



scrape_configs:

- job_name: 'prometheus'

static_configs:
- targets: ['localhost:9090']

- job_name: 'radios-service'


metrics_path: '/prometheus-metrics'
static_configs:
- targets: ['radios-service:8080']

- job_name: 'websocket-service'
metrics_path: '/prometheus-websocket'
static_configs:
- targets: ['websocket-service:8080']

这可以通过我的命令行在docker上成功运行,但是当我尝试在vm上运行它时会抛出此错误:

ERROR: for prometheus Cannot start service prometheus: b'OCI runtime create failed: container_linux.go:348: starting container process caused "process_linux.go:402: container init caused \"rootfs_linux.go:58: mounting \\"/usr/local/bin/prometheus.yml\\" to rootfs \\"/var/lib/docker/overlay2/f4b34c5866b191683d4e8c08e59fb14f56127cbcd67a603225954dd59c0a6a50/merged\\" at \\"/var/lib/docker/overlay2/f4b34c5866b191683d4e8c08e59fb14f56127cbcd67a603225954dd59c0a6a50/merged/etc/prometheus/prometheus.yml\\" caused \\"not a directory\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type' ERROR: Encountered errors while bringing up the project.



但是当我在本地运行它不会引发任何问题。虚拟机中的问题可能是什么?

最佳答案

我通过在docker compose中编辑卷行来解决它。我猜在Linux机器上,您需要提供绝对路径。我将prometheus.yml放在/ home /目录中,并将路径更改为如下所示:

prometheus:
image: prom/prometheus:v2.1.0
volumes:
- /home/prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
ports:
- '9090:9090'

这似乎有效。

关于docker - Prometheus不是在vm上运行,而是在本地Docker上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51267889/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com