Metrics collection compose example.
Educational example only. Review every volume path, port, and credential before you run this. Do not copy production secrets into your wiki or git repo.
_shared/.env for non-secrets, _shared/.secret for credentialsmkdir -p /path/to/docker/stacks/prometheus
cd /path/to/docker/stacks/prometheus
# paste compose.yaml below, then:
docker compose pull
docker compose up -d
---
services:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
hostname: prometheus
env_file:
- /path/to/docker/stacks/_shared/.env
- /path/to/docker/stacks/_shared/.secret
command:
- '--storage.tsdb.retention.time=60d'
- '--config.file=/etc/prometheus/prometheus.yml'
mem_limit: 1g
cpu_shares: 768
security_opt:
- no-new-privileges=true
user: 0:0
healthcheck:
test: wget --no-verbose --tries=1 --spider http://localhost:9090/ || exit 1
logging:
driver: json-file
options:
max-file: ${DOCKERLOGGING_MAXFILE:-10} # Max number of log files
max-size: ${DOCKERLOGGING_MAXSIZE:-200k} # Max file size
ports:
- 9090:9090
volumes:
- /path/to/docker/data/prometheus:/prometheus:rw
- /path/to/docker/stacks/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:rw
restart: unless-stopped