Kitloft

All tools / Docker Compose examples

Prometheus with Docker Compose

Prometheus with its config inline in the Compose file and a named volume for its data.

Customize names, versions →

compose.yaml
services:
  prometheus:
    image: prom/prometheus:v3.4.0
    restart: unless-stopped
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - --storage.tsdb.path=/prometheus
      - --storage.tsdb.retention.time=15d
      - --web.enable-lifecycle
    configs:
      - source: prometheus_config
        target: /etc/prometheus/prometheus.yml
    volumes:
      - prometheus-data:/prometheus
    ports:
      - "127.0.0.1:9090:9090"

configs:
  prometheus_config:
    content: |
      global:
        scrape_interval: 30s
      scrape_configs:
        - job_name: prometheus
          static_configs:
            - targets: ["localhost:9090"]
        # - job_name: my-app
        #   static_configs:
        #     - targets: ["my-app:8080"]

volumes:
  prometheus-data:

How to use it

Commands
docker compose up -d
docker compose ps
docker compose logs -f

Prefer Kubernetes? See the Prometheus Kubernetes version.