Docker Compose ist mehr als “docker compose up”. Hier sind 10 fortgeschrittene Techniken.
1. Profiles¶
services: debug: profiles: [debug]
docker compose –profile debug up¶
2. YAML Anchors¶
x-common: &common restart: unless-stopped services: app: <<: *common
3. Health Checks + depends_on¶
services: db: healthcheck: test: [“CMD-SHELL”, “pg_isready”] app: depends_on: db: { condition: service_healthy }
4. Env-Dateien¶
env_file: [.env, .env.local]
5. Benannte Volumes¶
volumes: pgdata: services: db: volumes: [“pgdata:/var/lib/postgresql/data”]
6. Interne Netzwerke¶
networks: backend: { internal: true }
7. Ressourcenlimits¶
deploy: resources: limits: { memory: 512M, cpus: “1.0” }
8. Multi-File Compose¶
docker compose -f compose.yml -f compose.prod.yml up
9. Init Container¶
migrate: command: [“python”, “manage.py”, “migrate”] app: depends_on: migrate: { condition: service_completed_successfully }
10. Watch-Modus¶
develop: watch: - action: sync path: ./src target: /app/src
Tipp¶
Profiles für Dev/Prod, Health Checks für die Startreihenfolge, YAML Anchors gegen Duplizierung.