Blueprints · Docker & Databases
Production
15 min · Grafana / Prometheus
Grafana and Prometheus localhost bind
Publishes Grafana and Prometheus on localhost so the dashboards and the metrics scrape endpoint are not a public login.
Why this should not be public
Prometheus has no authentication, and its targets and labels reveal internal hostnames, versions and sometimes credentials. A public Grafana login attracts password guessing, and Grafana has had path-traversal bugs that read server files (CVE-2021-43798).
Live config
Baked-in protections
- Grafana is on 127.0.0.1:3000
- Prometheus is on 127.0.0.1:9090
- Neither service is privileged
Step 1 · yaml
Compose file
/opt/metrics/compose.yaml
Set an admin password in the environment before the first start. Prometheus has no login of its own, so the bind is the control.
services:
prometheus:
image: prom/prometheus:v2.55.0
ports:
- "127.0.0.1:9090:9090"
security_opt:
- no-new-privileges:true
restart: unless-stopped
grafana:
image: grafana/grafana:11.3.0
environment:
GF_SECURITY_ADMIN_PASSWORD: change-me
GF_USERS_ALLOW_SIGN_UP: "false"
ports:
- "127.0.0.1:3000:3000"
security_opt:
- no-new-privileges:true
restart: unless-stopped
Step 2 · bash
Start script
/opt/metrics/up.sh
Written, not run.
#!/bin/sh set -eu if grep -q 'change-me' "/opt/metrics/compose.yaml"; then echo "Set GF_SECURITY_ADMIN_PASSWORD before starting." >&2 exit 1 fi cd "/opt/metrics" docker compose up -d