Generate a compose.yaml for your app, database and cache with health-checked startup, named volumes and secrets in .env, validated with docker compose config.
---
name: docker-compose-generator
description: Writes a Docker Compose file (compose.yaml) for local development or a single-host deployment of the project's services — app, database, cache, workers — with health-checked startup order, named volumes and secrets kept in .env, then validates it with docker compose config. Use when asked to containerise a stack, add Postgres/Redis/MySQL alongside an app, or fix a docker-compose.yml.
compatibility: Validation needs Docker Compose v2 (docker compose). Starting containers is optional and needs a running Docker daemon.
metadata:
version: "1.2.0"
---
# Docker Compose Generator
Produce a Compose file that matches the real project: its Dockerfile stages, ports, environment variables and backing services.
## When not to use
- Production orchestration across several hosts (use Kubernetes manifests or the platform's own format).
- The project has no Dockerfile and the user does not want one; write the Dockerfile first or use an official runtime image with a bind mount.
## Inputs to collect
- Services and versions (for example Node 22 app, PostgreSQL 17, Redis 7) and how the app reads its configuration.
- Ports the app listens on; whether ports should be reachable only from this machine.
- Development (bind mounts, hot reload) or single-host production (no source mounts, restart policy, resource limits).
- Existing `.env`, `.env.example` or Dockerfile targets.
## Workflow
1. Read the Dockerfile (stages, `EXPOSE`, `CMD`) and the app's config to find required environment variables.
2. Write `compose.yaml`:
- No top-level `version:` key — it is obsolete and Compose warns about it.
- Credentials come from interpolation, never literals: `${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}` fails fast when unset. Put sample values in `.env.example`, keep `.env` out of git.
- `depends_on` with `condition: service_healthy` only for services that define a `healthcheck`; escape container-side variables in healthchecks as `$${VAR}`.
- Named volumes for database data. Mount path depends on the image: PostgreSQL 17 and earlier use `/var/lib/postgresql/data`; the official postgres 18+ images declare `/var/lib/postgresql`.
- Bind published ports to `127.0.0.1` in development unless other machines need access.
- Services share the default network; add custom networks only to isolate groups.
3. Validate: `docker compose config -q` (syntax and interpolation; needs `.env` present) and `docker compose config` to review the resolved file. Fix every warning.
4. Optional, with the user's go-ahead: `docker compose up -d`, then `docker compose ps` and `docker compose logs <service>` to confirm health.
5. Hand off: list the files written (`compose.yaml`, `.env.example`, `.gitignore` entry) and the commands to start and stop (`docker compose down`; `down -v` deletes volumes — warn before suggesting it).
## Output format
`compose.yaml`, `.env.example`, the validation output, and a short table of service → image/build → ports → volumes → health check.
## Example (Node app + PostgreSQL 17 + Redis, development)
```yaml
services:
app:
build:
context: .
target: dev
ports:
- "127.0.0.1:3000:3000"
environment:
DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}
REDIS_URL: redis://redis:6379
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
volumes:
- ./src:/app/src
db:
image: postgres:17
environment:
POSTGRES_USER: ${POSTGRES_USER:?set POSTGRES_USER in .env}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}
POSTGRES_DB: ${POSTGRES_DB:-app}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
interval: 5s
timeout: 5s
retries: 10
redis:
image: redis:7-alpine
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10
volumes:
postgres_data:
```
`.env.example`
```
POSTGRES_USER=app
POSTGRES_PASSWORD=change-me
POSTGRES_DB=app
```
## Limitations
- `docker compose config` does not build images or prove the app connects; only `up` and the app's own health endpoint show that.
- Image tags drift; pin the major version you tested and check the image's documentation when upgrading majors (data directory layouts can change).
Generate a GitHub Actions (or other CI) pipeline from the repo's real scripts, with least-privilege permissions, caching, concurrency and a gated deploy.
Automate notifications and alerts
Automate report generation
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
A Node.js API with a multi-stage Dockerfile (target dev) needs PostgreSQL 17 and Redis for local development.
Create a compose file for local dev: our Node API (Dockerfile target 'dev', listens on 3000, reads DATABASE_URL and REDIS_URL) plus Postgres 17 and Redis 7. Don't put passwords in the file.
compose.yaml with services app, db and redis and no top-level `version:`. The app builds target dev, publishes 127.0.0.1:3000:3000 and builds DATABASE_URL from ${POSTGRES_USER}/${POSTGRES_PASSWORD}/${POSTGRES_DB}. It depends_on db and redis with condition: service_healthy; both define healthchecks (pg_isready with $$-escaped variables, redis-cli ping). Postgres data goes to a named volume at /var/lib/postgresql/data, and POSTGRES_PASSWORD uses ${POSTGRES_PASSWORD:?...} so a missing .env fails loudly. Also written: .env.example, a reminder to gitignore .env, and the `docker compose config -q` result.AI Agent Skills are reusable workflow packages that extend your AI coding assistant with multi-step capabilities. Install docker-compose-generator by following these steps.
SKILL.md inside, in the location documented by your client. Do not assume every AI application reads the same directory.Requires an Agent Skills-compatible client; supported locations and activation vary by version. Read the SKILL.md setup guide. MCP connects tools and data and does not, by itself, install a skill.