$npx -y skills add girijashankarj/cursor-handbook --skill docker-compose-generatorGenerate docker-compose.yml files for local development with application services, databases, caches, and queues. Use when the user asks to set up a local dev environment or create docker-compose configuration.
| 1 | # Skill: Docker Compose Generator |
| 2 | |
| 3 | Generate a complete `docker-compose.yml` for local development with all required services, health checks, and networking. |
| 4 | |
| 5 | ## Trigger |
| 6 | When the user asks to create a docker-compose file, set up a local dev environment, or add services to an existing compose config. |
| 7 | |
| 8 | ## Prerequisites |
| 9 | - [ ] Application services identified |
| 10 | - [ ] Dependencies identified (database, cache, queue, etc.) |
| 11 | - [ ] Port requirements known |
| 12 | |
| 13 | ## Steps |
| 14 | |
| 15 | ### Step 1: Identify Required Services |
| 16 | |
| 17 | | Service | Image | Default Port | |
| 18 | |---------|-------|-------------| |
| 19 | | **PostgreSQL** | `postgres:16-alpine` | 5432 | |
| 20 | | **MySQL** | `mysql:8.0` | 3306 | |
| 21 | | **MongoDB** | `mongo:7` | 27017 | |
| 22 | | **Redis** | `redis:7-alpine` | 6379 | |
| 23 | | **OpenSearch** | `opensearchproject/opensearch:2` | 9200 | |
| 24 | | **RabbitMQ** | `rabbitmq:3-management-alpine` | 5672, 15672 | |
| 25 | | **Kafka** | `confluentinc/cp-kafka:7.5.0` | 9092 | |
| 26 | | **LocalStack** | `localstack/localstack:latest` | 4566 | |
| 27 | | **Mailhog** | `mailhog/mailhog` | 1025, 8025 | |
| 28 | | **MinIO** | `minio/minio` | 9000, 9001 | |
| 29 | |
| 30 | ### Step 2: Generate Base Compose File |
| 31 | |
| 32 | ```yaml |
| 33 | version: "3.9" |
| 34 | |
| 35 | services: |
| 36 | app: |
| 37 | build: |
| 38 | context: . |
| 39 | dockerfile: Dockerfile |
| 40 | target: deps |
| 41 | volumes: |
| 42 | - .:/app |
| 43 | - /app/node_modules |
| 44 | ports: |
| 45 | - "${APP_PORT:-3000}:3000" |
| 46 | environment: |
| 47 | - NODE_ENV=development |
| 48 | - DB_HOST=postgres |
| 49 | - DB_PORT=5432 |
| 50 | - DB_NAME=${DB_NAME:-myapp} |
| 51 | - DB_USERNAME=${DB_USERNAME:-postgres} |
| 52 | - DB_PASSWORD=${DB_PASSWORD:-postgres} |
| 53 | - REDIS_URL=redis://redis:6379 |
| 54 | depends_on: |
| 55 | postgres: |
| 56 | condition: service_healthy |
| 57 | redis: |
| 58 | condition: service_healthy |
| 59 | restart: unless-stopped |
| 60 | ``` |
| 61 | |
| 62 | ### Step 3: Add Database Service |
| 63 | |
| 64 | ```yaml |
| 65 | postgres: |
| 66 | image: postgres:16-alpine |
| 67 | ports: |
| 68 | - "${DB_PORT:-5432}:5432" |
| 69 | environment: |
| 70 | POSTGRES_DB: ${DB_NAME:-myapp} |
| 71 | POSTGRES_USER: ${DB_USERNAME:-postgres} |
| 72 | POSTGRES_PASSWORD: ${DB_PASSWORD:-postgres} |
| 73 | volumes: |
| 74 | - postgres_data:/var/lib/postgresql/data |
| 75 | - ./scripts/init-db.sql:/docker-entrypoint-initdb.d/init.sql |
| 76 | healthcheck: |
| 77 | test: ["CMD-SHELL", "pg_isready -U postgres"] |
| 78 | interval: 10s |
| 79 | timeout: 5s |
| 80 | retries: 5 |
| 81 | restart: unless-stopped |
| 82 | ``` |
| 83 | |
| 84 | ### Step 4: Add Cache Service |
| 85 | |
| 86 | ```yaml |
| 87 | redis: |
| 88 | image: redis:7-alpine |
| 89 | ports: |
| 90 | - "${REDIS_PORT:-6379}:6379" |
| 91 | volumes: |
| 92 | - redis_data:/data |
| 93 | healthcheck: |
| 94 | test: ["CMD", "redis-cli", "ping"] |
| 95 | interval: 10s |
| 96 | timeout: 5s |
| 97 | retries: 5 |
| 98 | restart: unless-stopped |
| 99 | ``` |
| 100 | |
| 101 | ### Step 5: Add Queue / Search / Other Services |
| 102 | - [ ] Add services based on project requirements |
| 103 | - [ ] Include health checks for every service |
| 104 | - [ ] Use environment variables for configurable ports |
| 105 | - [ ] Add management UIs where available (RabbitMQ, OpenSearch Dashboards) |
| 106 | |
| 107 | ### Step 6: Add Volumes and Networks |
| 108 | |
| 109 | ```yaml |
| 110 | volumes: |
| 111 | postgres_data: |
| 112 | driver: local |
| 113 | redis_data: |
| 114 | driver: local |
| 115 | |
| 116 | networks: |
| 117 | default: |
| 118 | name: ${COMPOSE_PROJECT_NAME:-myapp}_network |
| 119 | ``` |
| 120 | |
| 121 | ### Step 7: Create Helper Scripts |
| 122 | - [ ] `docker-compose up -d` wrapper with health check waiting |
| 123 | - [ ] Database seed script |
| 124 | - [ ] Reset script (destroy volumes, recreate) |
| 125 | |
| 126 | ```bash |
| 127 | # scripts/dev-setup.sh |
| 128 | #!/usr/bin/env bash |
| 129 | set -euo pipefail |
| 130 | |
| 131 | echo "Starting services..." |
| 132 | docker compose up -d |
| 133 | |
| 134 | echo "Waiting for database..." |
| 135 | until docker compose exec postgres pg_isready -U postgres; do |
| 136 | sleep 2 |
| 137 | done |
| 138 | |
| 139 | echo "Running migrations..." |
| 140 | npm run migrate |
| 141 | |
| 142 | echo "Dev environment ready!" |
| 143 | ``` |
| 144 | |
| 145 | ### Step 8: Create .env for Docker |
| 146 | ```bash |
| 147 | # .env.docker (for docker-compose) |
| 148 | COMPOSE_PROJECT_NAME=myapp |
| 149 | APP_PORT=3000 |
| 150 | DB_PORT=5432 |
| 151 | DB_NAME=myapp |
| 152 | DB_USERNAME=postgres |
| 153 | DB_PASSWORD=postgres |
| 154 | REDIS_PORT=6379 |
| 155 | ``` |
| 156 | |
| 157 | ### Step 9: Update .dockerignore |
| 158 | ``` |
| 159 | node_modules |
| 160 | .git |
| 161 | .env |
| 162 | .env.* |
| 163 | dist |
| 164 | coverage |
| 165 | *.log |
| 166 | ``` |
| 167 | |
| 168 | ## Rules |
| 169 | - **ALWAYS** pin image versions (no `:latest` except for dev-only tools) |
| 170 | - **ALWAYS** include health checks for every service |
| 171 | - **ALWAYS** use named volumes for data persistence |
| 172 | - **ALWAYS** use environment variables for ports and credentials |
| 173 | - **NEVER** use production credentials in compose files |
| 174 | - **NEVER** expose management ports in production compose files |
| 175 | - Use `depends_on` with `condition: service_healthy` for startup ordering |
| 176 | - Add `restart: unless-stopped` for resilient local dev |
| 177 | |
| 178 | ## Completion |
| 179 | Complete `docker-compose.yml` with all services, health checks, volumes, and helper scripts. Ready to run with `docker compose up`. |
| 180 | |
| 181 | ## If a Step Fails |
| 182 | - **Port conflict:** Use environment variables to override ports |
| 183 | - **Image pull fails:** Check network, verify image name and tag exist |
| 184 | - **Health check fails:** Increase timeout/retries, check service logs |
| 185 | - **Volume permission issue |