Learn Labs
Foundations

Docker & Setup

The minimal and full stacks, and what each container does

Like the Postgres and ClickHouse modules, everything runs in Docker. This module has two compose files in prometheus/:

  • compose.yaml: two containers, Prometheus and Grafana. Use it for the first lessons, where the only thing being monitored is Prometheus itself.
  • compose_prod.yaml: the full stack, used from Your First Scrape onward.

The minimal stack

services:
prometheus:
  image: prom/prometheus:v3.15.0
  ports:
    - "9090:9090"
  volumes:
    - ./config/prometheus.minimal.yml:/etc/prometheus/prometheus.yml:ro
    - prometheus_data:/prometheus

grafana:
  image: grafana/grafana:13.2.3
  ports:
    - "3001:3000"   # 3000 on the host is taken by the website dev server
  volumes:
    - ../grafana/provisioning/datasources:/etc/grafana/provisioning/datasources:ro
    - grafana_data:/var/lib/grafana

volumes:
prometheus_data:
grafana_data:

And the config it mounts, which tells Prometheus to scrape exactly one target, itself:

global:
scrape_interval: 15s

scrape_configs:
- job_name: prometheus
  static_configs:
    - targets: ["localhost:9090"]
cd prometheus
cp .env.example .env
docker compose up -d

open http://localhost:9090        # Prometheus
open http://localhost:3001        # Grafana, admin / admin123

Prometheus keeps its database in the prometheus_data volume at /prometheus. Grafana keeps users, sessions, and any dashboards you save in the UI in grafana_data. As with Postgres, docker compose down keeps both volumes, and down -v deletes them.

The full stack

compose_prod.yaml adds everything a real deployment has, plus a demo app to measure:

compose_prod.yaml services
prometheusscrapes, stores, evaluates rules. :9090alertmanagergroups, routes, silences alerts. :9093grafanadashboards, provisioned from ../grafana. :3001node-exporterCPU, memory, disk, network of the Docker hostblackbox-exporterprobes URLs and ports from the outsidepostgres-exporterturns pg_stat_* views into metricspushgatewayholds metrics pushed by short-lived jobs. :9091demo-appinstrumented Python service. :8080loadgensteady traffic to demo-app
docker compose down                               # stop the minimal stack first
docker compose -f compose_prod.yaml up -d --build   # builds demo-app the first time
docker compose -f compose_prod.yaml ps

A few details in compose_prod.yaml are worth reading closely, because they're what separates a toy setup from a real one.

Prometheus flags. The command: block replaces the image defaults:

--config.file=/etc/prometheus/prometheus.ymlthe whole config/ dir is mounted read-only--storage.tsdb.path=/prometheusTSDB location, on the named volume--storage.tsdb.retention.time=15ddelete blocks older than 15 days--storage.tsdb.retention.size=5GB...or when the TSDB passes 5 GB, whichever is first--web.enable-lifecycleallows POST /-/reload--web.enable-remote-write-receiveraccepts remote_write from other Prometheus servers

Shared defaults. A YAML anchor (x-defaults: &defaults) gives every service the same restart policy, network, and log rotation. Without max-size, a chatty container's JSON log file grows until the disk is full, and the disk-full alert you'll write later is the one thing that can't fire.

Reaching the other modules. Postgres and ClickHouse run in their own compose projects, on different Docker networks. The exporters reach them through the host, using host.docker.internal, with extra_hosts: ["host.docker.internal:host-gateway"] so the name also resolves on Linux.

Grafana provisioning. ../grafana/provisioning and ../grafana/dashboards are mounted read-only. Data sources and three dashboards appear on first start, with nothing clicked by hand. That's covered in Dashboards as Code.

Everyday commands

# validate config and rules before reloading
docker exec prometheus promtool check config /etc/prometheus/prometheus.yml

# reload config without restarting (keeps in-memory data)
curl -X POST localhost:9090/-/reload

# logs
docker logs -f prometheus

# stop, keep data
docker compose -f compose_prod.yaml stop

# wipe stored metrics and Grafana state
docker compose -f compose_prod.yaml down -v

Next: what each of these containers actually does, and how they fit together. See Architecture.

On this page