From Containers to Observability: Docker Compose Roadmap¶
Monitoring (Prometheus & Grafana)¶
Metrics monitoring allows you to see numbers (CPU, RAM, Request counts) over time.
Prometheus: Collects and stores metrics (The Database).
Grafana: Visualizes the metrics (The Dashboard).
Project Structure¶
project06/
├── docker-compose.yaml
└── prometheus.yml
Step 1: The Prometheus Config¶
global:
scrape_interval: 5s # Wie oft Prometheus Daten abfragt (Standard ist 15s)
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['prometheus:9090'] # Wir nutzen den Servicenamen statt localhost
Step 2: The Compose File¶
services:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus # Speichert Metriken dauerhaft
grafana:
image: grafana/grafana:latest
container_name: grafana
ports:
- "3000:3000"
depends_on:
- prometheus
volumes:
- grafana_data:/var/lib/grafana # Verhindert Datenverlust der Dashboards
volumes:
prometheus_data:
grafana_data:
Practical Exercise: View the Dashboard¶
Start the stack:
docker-compose up -d
Check if containers are running:
docker psOpen Prometheus (Targets check):
http://localhost:9090/targets
Open Grafana (Initial Setup):
http://localhost:3000
(Default Login: admin / admin)
Clean up (Important before next project):
docker-compose down
Alerting (Mattermost & Webhooks)¶
Project Structure¶
project07/
└── docker-compose.yaml
Step 1: The Compose File¶
services:
mattermost:
image: mattermost/mattermost-preview
container_name: mattermost
ports:
- "8065:8065"
# Preview Image nutzt eine interne DB, ideal für Tests
Step 2: Integration Logic¶
Open Mattermost:
http://localhost:8065
Setup: Erstelle einen Account und ein Team “DevOps”.
Webhook: Gehe zu Product Settings -> Integrations -> Incoming Webhooks.
Grafana Link: In Grafana unter Alerting -> Contact Points den Typ “Webhook” wählen.
Test the Alert:
# Simuliere Last oder stoppe einen Service, um Alarm zu triggern docker-compose stop mattermost
Logging (The ELK Stack)¶
ElasticSearch: Search engine for logs.
Logstash: (Optional in basic setups) Processes logs.
Kibana: The interface.
Project Structure¶
project08/
└── docker-compose.yaml
Step 1: The Compose File¶
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.10.2
container_name: elasticsearch
environment:
- discovery.type=single-node # Verhindert Cluster-Suche (spart Ressourcen)
- xpack.security.enabled=false # Deaktiviert Auth für lokale Tests
- "ES_JAVA_OPTS=-Xms512m -Xmx512m" # Begrenzt RAM-Verbrauch der JVM
ports:
- "9200:9200"
ulimits:
memlock:
soft: -1
hard: -1
kibana:
image: docker.elastic.co/kibana/kibana:8.10.2
container_name: kibana
ports:
- "5601:5601"
environment:
- ELASTICSEARCH_HOSTS=http://elasticsearch:9200
depends_on:
- elasticsearch
Practical Exercise: Searching Logs¶
Start (Wait for healthy status):
docker-compose up -d
Verify Elasticsearch is “Green”:
http://localhost:9200/_cluster/health?pretty
Access Kibana:
http://localhost:5601
Data View: In Kibana unter Stack Management -> Data Views einen Index (z.B. *) erstellen, um Logs zu sehen.
Summary of Learning Path¶
Tool |
Best For |
Docker Skill Learned |
|---|---|---|
Prometheus |
Numbers/Metrics |
Target Scraping & Config Mounting |
Mattermost |
Alerts/Chat |
Webhooks & External API links |
ELK Stack |
Text/Error Logs |
Resource Limits (RAM/Java Opts) |