I want to run the prometheus as docker instance with mounting file on /var/run/docker.sock, as I want to monitor the hosts from docker.sock file. Currently, I am successfully running the prometheus on host machines using prometheus cli command.
However, when I have mounted the file /var/run/docker.sock from docker cli, I cannot discover the nodes on prometheus web panel that are live in docker.sock file. It implies that docker containers cannot access the docker.sock file. Morover, the read/write access has been granted to docker containers while mounting the file.
Run Prometheus using commands:
./prometheus --config.file /home/**********/prom_conf/prometheus.yml
Prometheus configuration:
# my global config
global:
scrape_interval: 5s
scrape_timeout: 3s
evaluation_interval: 15s
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
- 127.0.0.1:5050
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
- "alert_rules.yml"
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
static_configs:
- targets:
['localhost:9100']
- job_name: 'dockerswarm'
dockerswarm_sd_configs:
- host: unix:///var/run/docker.sock
role: tasks
relabel_configs:
# Only keep containers that should be running.
- source_labels: [__meta_dockerswarm_task_desired_state]
regex: running
action: keep
# Only keep containers that have a `prometheus-job` label.
- source_labels: [__meta_dockerswarm_service_label_prometheus_job]
regex: .+
action: keep
# Use the prometheus-job Swarm label as Prometheus job label.
- source_labels: [__meta_dockerswarm_service_label_prometheus_job]
target_label: job
Prometheus with docker-cli:
docker run
-p 9090:9090
-v /home/**************/prom_conf:/etc/prometheus
-v /var/run/docker.sock:/var/run/docker.sock
-v /sys/fs/cgroup:/cgroup
-v /:/rootfs:ro
prom/prometheus
Source: Docker Questions