Skip to main content
DevOps Insightsguides & answers

How to monitor Docker containers with Prometheus?

Answered
6mo ago·358 views
4

Prometheus and Grafana are the usual answer for monitoring Docker containers, but "use Prometheus" leaves out the part that does the work: something has to expose per-container metrics before Prometheus has anything to scrape.

What the minimum working stack is, and what each piece in it is actually for.

1 Answer

Accepted Answer

Use cAdvisor to expose container metrics, then scrape with Prometheus.

Quick setup with Docker Compose:

yaml
services:
  prometheus:
    image: prom/prometheus:v3.15.0
    ports: ["127.0.0.1:9090:9090"]
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml

  grafana:
    image: grafana/grafana:13.2.3
    ports: ["127.0.0.1:3000:3000"]

  cadvisor:
    image: ghcr.io/google/cadvisor:0.60.6
    ports: ["127.0.0.1:8080:8080"]
    volumes:
      - /:/rootfs:ro
      - /var/run:/var/run:ro
      - /sys:/sys:ro
      - /var/lib/docker:/var/lib/docker:ro

Prometheus only scrapes what prometheus.yml lists, so give it a job for cAdvisor:

yaml
scrape_configs:
  - job_name: cadvisor
    static_configs:
      - targets: ["cadvisor:8080"]

See our full Monitoring with Prometheus & Grafana article for dashboards and alerting.

Neeraj JhaEditor
6mo ago
9

Your Answer

Sign in to answer with your account, or give a name to answer without one.

Shown with your answer. 2 to 50 letters, numbers or spaces; up to 10 answers an hour without an account.

Used AI to write this? That is fine — say so in your post, and run any command before you suggest it. Answers that are AI-generated without saying so, or that were never tested, may be removed. Forum policy

Supports Markdown: **bold**, *italic*, `code`, ```code blocks```