I'm trying to get prometheus running on the vm. I have several microservices which I wish to monitor and are running on the vm. I added the below to one of the docker-compose.yml files :
prometheus:
image: prom/prometheus:v2.1.0
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
ports:
- '9090:9090'
And I added my prometheus.yml file in the same folder as the above 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']
This runs successfully on docker through my command line.However, it throws this error when i try to run it on the 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.
But it does not throw any issue when i run it locally. What could the issue in the vm be?
I solved it by editing the volumes line in the docker compose. I guess in a linux machine you need to provide the absolute path. I placed my prometheus.yml in a /home/ directory and changed the path to that as below:
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'
That seems to work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.