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 / admin123Prometheus 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.
Grafana's default port is 3000, which is also where pnpm dev runs this
website. The compose files publish Grafana on host port 3001. If you
see the docs site when you expected Grafana, you're on the wrong port.
The full stack
compose_prod.yaml adds everything a real deployment has, plus a demo
app to measure:
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 psA 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:
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 -vAlways run promtool check config before /-/reload. If the new config
is invalid, the reload fails and Prometheus keeps running the old
config, which is safe. But the only sign is a log line and the
prometheus_config_last_reload_successful metric dropping to 0. Many
teams have "changed" a config that never took effect. There's an alert
for exactly this in Operating Prometheus.
Next: what each of these containers actually does, and how they fit together. See Architecture.