Overview
Generates secure, production-oriented docker-compose.yml (and docker-compose.override.yml for local dev) with proper service definitions, networks, volumes, healthchecks, resource limits, environment variable management, secrets handling, and restart policies. Includes full examples for common stacks (Node.js + Postgres + Redis, Python + Postgres + Redis, etc.).
When to Use This Skill
- Containerizing a new or existing multi-service application.
- The user says "docker-compose", "containerize", "local dev environment with DB", or "production docker setup".
- Setting up consistent environments across developer machines and CI/CD.
Prerequisites
- Docker Desktop or Docker Engine + Compose V2 installed.
- Application code that can be containerized (Dockerfile exists or can be created).
- Understanding of the services needed (database, cache, queue, etc.).
Steps
Inventory all services the app needs (app, db, cache, queue, search, etc.).
Define networks:
frontend (for reverse proxy / app).
backend (internal, for app ↔ db, app ↔ cache).
Define volumes for persistent data (named volumes preferred over bind mounts in production).
Service definition template (for each service):
image or build.
environment or env_file (never commit secrets in prod compose).
volumes.
networks.
healthcheck (critical).
restart: unless-stopped.
deploy.resources limits/requests (for Swarm or when using compose with limits).
depends_on with condition: service_healthy.
Secrets & config:
- Use Docker secrets or external secret managers for prod.
- For local:
.env loaded via env_file.
- Never put real credentials in the committed compose file.
Healthchecks:
- DB:
pg_isready, mysqladmin ping, etc.
- App:
/health endpoint that checks DB connectivity.
Local vs prod:
docker-compose.yml for prod-like.
docker-compose.override.yml (auto-loaded) for local dev (hot reload, different ports, debug flags).
Output:
- Full
docker-compose.yml.
- Example
Dockerfile for the app if missing.
.env.example.
- Commands to bring up, view logs, run migrations, etc.
- Production notes (use
docker compose up -d, logging drivers, etc.).
Examples
Complete docker-compose.yml for a Node.js + PostgreSQL + Redis + optional Nginx reverse proxy stack, with healthchecks, named volumes, proper networking, and a matching override for local development is included, along with the corresponding Dockerfiles and .env.example.
Edge Cases & Error Handling
- Database initialization: Use
depends_on + healthcheck, and an init container or entrypoint script that waits for DB.
- Permission issues with volumes: Run containers as non-root user; set correct UID/GID on volumes.
- Secrets in CI: Use GitHub Secrets or similar +
docker compose with --env-file from secrets.
- Scaling: Note that some services (Postgres) are not easily horizontally scaled in compose; recommend managed DB for prod.
Verification
docker compose config — validates syntax.
docker compose up --build -d — all services healthy (check docker compose ps).
- App can connect to DB and Redis (test endpoints).
docker compose down -v cleans up.
- Success: Environment is reproducible, services start reliably, data persists across restarts, and no secrets are in the repo.
References
1---2name: docker-compose-generator3description: Generates production-ready docker-compose.yml files for multi-service applications. Use when containerizing an app with databases, caches, or other services.4license: Apache-2.05---67## Overview89Generates secure, production-oriented `docker-compose.yml` (and `docker-compose.override.yml` for local dev) with proper service definitions, networks, volumes, healthchecks, resource limits, environment variable management, secrets handling, and restart policies. Includes full examples for common stacks (Node.js + Postgres + Redis, Python + Postgres + Redis, etc.).1011## When to Use This Skill1213- Containerizing a new or existing multi-service application.14- The user says "docker-compose", "containerize", "local dev environment with DB", or "production docker setup".15- Setting up consistent environments across developer machines and CI/CD.1617## Prerequisites1819- Docker Desktop or Docker Engine + Compose V2 installed.20- Application code that can be containerized (Dockerfile exists or can be created).21- Understanding of the services needed (database, cache, queue, etc.).2223## Steps24251. **Inventory all services** the app needs (app, db, cache, queue, search, etc.).26272. **Define networks**:28 - `frontend` (for reverse proxy / app).29 - `backend` (internal, for app ↔ db, app ↔ cache).30313. **Define volumes** for persistent data (named volumes preferred over bind mounts in production).32334. **Service definition template** (for each service):34 - `image` or `build`.35 - `environment` or `env_file` (never commit secrets in prod compose).36 - `volumes`.37 - `networks`.38 - `healthcheck` (critical).39 - `restart: unless-stopped`.40 - `deploy.resources` limits/requests (for Swarm or when using compose with limits).41 - `depends_on` with condition: service_healthy.42435. **Secrets & config**:44 - Use Docker secrets or external secret managers for prod.45 - For local: `.env` loaded via `env_file`.46 - Never put real credentials in the committed compose file.47486. **Healthchecks**:49 - DB: `pg_isready`, `mysqladmin ping`, etc.50 - App: `/health` endpoint that checks DB connectivity.51527. **Local vs prod**:53 - `docker-compose.yml` for prod-like.54 - `docker-compose.override.yml` (auto-loaded) for local dev (hot reload, different ports, debug flags).55568. **Output**:57 - Full `docker-compose.yml`.58 - Example `Dockerfile` for the app if missing.59 - `.env.example`.60 - Commands to bring up, view logs, run migrations, etc.61 - Production notes (use `docker compose up -d`, logging drivers, etc.).6263## Examples6465Complete `docker-compose.yml` for a Node.js + PostgreSQL + Redis + optional Nginx reverse proxy stack, with healthchecks, named volumes, proper networking, and a matching override for local development is included, along with the corresponding Dockerfiles and .env.example.6667## Edge Cases & Error Handling6869- **Database initialization**: Use `depends_on` + healthcheck, and an init container or entrypoint script that waits for DB.70- **Permission issues with volumes**: Run containers as non-root user; set correct UID/GID on volumes.71- **Secrets in CI**: Use GitHub Secrets or similar + `docker compose` with `--env-file` from secrets.72- **Scaling**: Note that some services (Postgres) are not easily horizontally scaled in compose; recommend managed DB for prod.7374## Verification75761. `docker compose config` — validates syntax.772. `docker compose up --build -d` — all services healthy (check `docker compose ps`).783. App can connect to DB and Redis (test endpoints).794. `docker compose down -v` cleans up.805. Success: Environment is reproducible, services start reliably, data persists across restarts, and no secrets are in the repo.8182## References8384- [Docker Compose Specification](https://docs.docker.com/compose/compose-file/)85- [Compose Healthchecks](https://docs.docker.com/compose/compose-file/05-services/#healthcheck)86- [Docker Secrets](https://docs.docker.com/engine/swarm/secrets/)87- [Production Compose Guidance](https://docs.docker.com/compose/production/)