compose-local-dev-stack
Skill9 starsChanged 5 months agoApache-2.0View on GitHub
Wires a local multi-service development stack with Docker Compose — app plus backing datastores (Postgres/Redis/Kafka), dependency-ordered healthchecks (depends_on condition: service_healthy), pinned images and named volumes, seed/init scripts, hot-reload bind mounts, profiles, and one-command up/down/reset via a Makefile.
- Reads credentials
In this repository147 other files it gives its agents.
- second-brain/AGENTS.mdAGENTS.md
- second-brain/CLAUDE.mdCLAUDE.md
- agent-tool-mcp-builderSkill
- api-design-reviewSkill
- async-concurrency-correctnessSkill
- audit-accessibility-wcagSkill
- audit-license-complianceSkill
- audit-technical-seoSkill
- auth-jwt-sessionSkill
- author-codemodSkill
- brainstorm-designSkill
- build-audit-loggingSkill
- build-cdc-streaming-pipelineSkill
- build-cli-toolSkill
- build-data-tableSkill
- build-etl-pipelineSkill
- build-form-validationSkill
- build-native-mobile-uiSkill
- build-office-docsSkill
- build-offline-first-syncSkill
- build-react-componentSkill
- build-realtime-channelSkill
- build-spreadsheetSkill
- build-vector-searchSkill
- caching-strategySkill
- cicd-pipeline-authorSkill
- cloud-cost-optimizeSkill
- code-commentsSkill
- code-reviewSkill
- configure-bundler-buildSkill
- configure-dns-tlsSkill
- configure-reverse-proxy-lbSkill
- configure-security-headers-cspSkill
- contract-testingSkill
- datetime-timezone-correctnessSkill
- db-migration-safetySkill
- debug-ci-pipeline-failureSkill
- debug-flaky-testsSkill
- debug-frontend-browserSkill
- debug-root-causeSkill
- defend-llm-prompt-injectionSkill
- deliver-webhooksSkill
- dependency-upgradeSkill
- deploy-releaseSkill
- design-api-paginationSkill
- design-authorization-modelSkill
- design-backup-dr-recoverySkill
- design-event-sourcing-cqrsSkill
- design-multi-tenancySkill
- design-protobuf-grpc-serviceSkill
- design-relational-schemaSkill
- design-search-index-infraSkill
- design-state-machineSkill
- design-token-systemSkill
- diff-table-paritySkill
- distributed-locks-leasesSkill
- dockerfile-optimizeSkill
- encrypt-sensitive-dataSkill
- error-messageSkill
- estimate-workSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 141
Ordering held: check docker compose logs migrate / app — the app started its first DB query *after* db was healthy and migrations …
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
When to Use
Reach for this when the request is about standing up the app's runtime dependencies on a laptop, reproducibly, with one command:
- "Get Postgres + Redis + the API running locally so I can develop"
- "The onboarding doc says
docker compose upbut it races / half the services aren't ready" - "Add Kafka (or a queue, or a second DB) to the local stack"
- "I want hot reload — edit code, see it without rebuilding the image"
- "Seed the dev database automatically" / "give me a clean-slate reset command"
NOT this skill:
- The container the editor/agent itself runs inside (devcontainer.json, features, VS Code attach) → setup-devcontainer-env
- Shrinking/hardening the production image (multi-stage, distroless, non-root) → dockerfile-optimize
- Deploying these services to a cluster (Deployments, probes, resource limits, Helm) → k8s-manifest-review
- Pinning the host language/tool versions (node/python/go via asdf/mise/
.tool-versions) → pin-toolchain-versions - A schema change's lock/data-loss safety → db-migration-safety (this skill only runs migrations on start)
Steps
One file, services as the unit. Pin every tag, name every volume. Floating
:latestmakes the stack non-reproducible and breaks silently on pull; bare anonymous volumes orphan and lose data ondown. Usecompose.yaml(the modern name — drop theversion:key, it's obsolete):name: myapp services: db: image: postgres:16.4-alpine # pin minor; never :latest environment: POSTGRES_USER: app POSTGRES_PASSWORD: app POSTGRES_DB: app volumes: - pgdata:/var/lib/postgresql/data # named -> survives `down` - ./db/init:/docker-entrypoint-initdb.d:ro # runs ONCE on empty volume healthcheck: test: ["CMD-SHELL", "pg_isready -U app -d app"] interval: 3s timeout: 3s retries: 20 start_period: 5s ports: ["5432:5432"] redis: image: redis:7.4-alpine command: ["redis-server", "--save", "", "--appendonly", "no"] # ephemeral cache healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 3s timeout: 2s retries: 20 app: build: { context: ., target: dev } # dev stage, not prod command: ["npm", "run", "dev"] # hot-reload command, overrides Dockerfile CMD depends_on: db: { condition: service_healthy } # waits for healthcheck, not just "started" redis: { condition: service_healthy } environment: DATABASE_URL: postgres://app:app@db:5432/app # use service name, not localhost REDIS_URL: redis://redis:6379 volumes: - ./src:/app/src # bind mount -> edits reflect live - /app/node_modules # anon vol masks host node_modules ports: ["3000:3000"] volumes: pgdata:Order startup with
depends_on: condition: service_healthy— never baredepends_on. Baredepends_ononly waits for the container to start, not to be ready; the app then connects to a Postgres still replaying WAL and crash-loops. The gate is the healthcheck on each backing service. Pick the right probe per service:Service Healthcheck test Why not just TCP Postgres pg_isready -U $USER -d $DBport opens before it accepts queries MySQL mysqladmin ping -h localhostsame early-port problem Redis redis-cli ping→PONGtrivial, do it Kafka (KRaft) kafka-broker-api-versions --bootstrap-server localhost:9092broker advertises before it serves metadata RabbitMQ rabbitmq-diagnostics -q pingmgmt port lies about readiness Elasticsearch curl -fsS localhost:9200/_cluster/health?wait_for_status=yellowgreen never comes single-node App migrations a one-shot migrateservice the appdepends_on(condition:service_completed_successfully)keeps schema setup off the app's hot path Tune
retries × interval ≥ real cold-start time(Kafka/ES needstart_period: 20s+) or healthy never arrives and the dependents abort.Seed once via
docker-entrypoint-initdb.d; run migrations every start via a one-shot service. The init dir (*.sql/*.sh, alphabetical) runs only when the data volume is empty — perfect for extensions, roles, and static seed (01-schema.sql,02-seed.sql). It does not re-run after the volume exists, so never put evolving migrations there. Migrations belong in a dedicated short-lived service the app waits on:migrate: build: { context: ., target: dev } command: ["npm", "run", "migrate:deploy"] # or: alembic upgrade head / flyway migrate depends_on: { db: { condition: service_healthy } } restart: "no"Then set
app.depends_on.migrate.condition: service_completed_successfully. Idempotent migration tools make this safe to run on everyup.- Hot reload = bind mount source + a dev
command+ a watcher, not a rebuild. Bind./src:/app/srcand run the dev server (npm run dev/uvicorn --reload/air/nodemon). Mask installed deps with an anonymous volume (- /app/node_modules) so the host's empty/mismatched dir doesn't shadow the image's. Build the image from adevstage (target: dev) that includes dev deps and the watcher — keep the lean prod stage for shipping (that's dockerfile-optimize's job). Changingpackage.json/requirements.txtstill needs a rebuild; code does not. - Split config: committed
compose.yaml+.env+ an uncommittedcompose.override.yml. Compose auto-mergescompose.override.ymlon top ofcompose.yamlwith no-fflag — put local-only tweaks there (extra port bindings, mounted debug tools,DEBUG=1) and gitignore it so teammates' hacks don't collide. Variables interpolate from.env(committed.env.example, real.envgitignored). Never hardcode host-specific ports or paths in the base file. - Gate optional services behind
profiles. Tag heavy/rarely-needed services (Kafka, a second DB, mailhog, a metrics stack) withprofiles: ["kafka"]so a plaindocker compose upstarts only the core stack. Opt in withdocker compose --profile kafka up. Keeps the default path fast; a service with noprofilesalways runs. - Use the default network and talk service-to-service by name; publish only the host ports you need. Compose gives you a default bridge network where services resolve each other by service name (
db,redis) — the app must usedb:5432, neverlocalhost:5432(localhost inside the app container is the app). Publish stable host ports (5432:5432) only for tools you run on the host (psql, a GUI). Collisions with a host Postgres → remap the host side (5433:5432), never the container side. Make one-command verbs in a
Makefile(orTaskfile.yml) so nobody memorizes flags.upmust block until healthy;resetmust wipe volumes:up: ## start core stack, wait until healthy docker compose up -d --wait down: ## stop, keep data docker compose down reset: ## stop AND wipe volumes -> clean slate docker compose down -v --remove-orphans docker compose up -d --wait logs: ## tail everything docker compose logs -f --tail=100 ps: docker compose ps--waitmakesupexit non-zero if any service never goes healthy — that's your machine-checkable gate.down -vis the only thing that deletes data; keep it onresetalone sodownis always safe.
Common Errors
- Bare
depends_on:(list form). Waits for container start, not readiness; the app races the DB and crash-loops on cold boot. Use the map form withcondition: service_healthy. - No
healthcheckon a backing service. Thenservice_healthyhas nothing to gate on and Compose errors or treats it as instantly up. Every service you depend-on needs a real probe (table in step 2). - App connects to
localhostinstead of the service name.localhostinside the app container is the app itself — connection refused. Usedb/redis/kafka(the service names) inDATABASE_URL/REDIS_URL. - Anonymous/missing volume on a datastore.
docker compose downorphans the anonymous volume and the nextupstarts empty; data "randomly" vanishes. Always name datastore volumes and declare them undervolumes:. - Expecting
docker-entrypoint-initdb.dto re-run. It runs only on an empty data volume. Edited a seed file and "nothing happened"? The volume already exists —docker compose down -v(ormake reset) to re-init. Don't put live migrations there. start_periodtoo short for Kafka/Elasticsearch. They take 20–60s to be ready; with the defaultstart_period: 0sand few retries, healthy never arrives and dependents abort. Setstart_period: 30sand enoughretries.:latest/ unpinned tags. A teammate pulls a newer Postgres major, the data dir format changes, the volume won't mount. Pin to a minor tag (postgres:16.4-alpine).- Host port already in use (
bind: address already in use). A host Postgres or a previous stack holds 5432. Remap the host side only (5433:5432); changing the container side breaks intra-network DNS. - Host
node_modules/venvshadowing the image's via the source bind mount. App can't find deps or loads wrong-arch binaries. Add the anonymous-volume mask (- /app/node_modules) after the source bind. - Secrets committed in
compose.yaml. Real credentials in the base file leak to git. Keep them in the gitignored.env; commit only.env.examplewith placeholders.
Verify
- Cold up from nothing:
make reset(wipes), thenmake up. The command must exit 0 —--waitfails the command if any service is unhealthy.docker compose psshows every core servicerunning (healthy). - Ordering held: check
docker compose logs migrate/ app — the app started its first DB query afterdbwas healthy and migrations completed, with no connection-refused retries in the log. - Seeded:
docker compose exec db psql -U app -d app -c "select count(*) from <seeded_table>;"returns the expected non-zero count without any manual step. - Hot reload: with the stack up, edit a source file under the bind mount → the app reloads and serves the change without
docker compose buildor restart. - Reachability: a host tool hits the published port (
psql -h localhost -p 5432 -U app), and the app reaches the DB by service name (nolocalhostin its config). - Reset is clean:
make resetrecreates the stack and the seeded count from step 3 matches again (volume truly wiped and re-init'd, not stale). - Profiles: plain
docker compose up -d --waitstarts only core services;--profile kafka upadditionally starts the gated ones;docker compose psconfirms each case. downis safe:make downthenmake uppreserves data (row count unchanged); onlymake resetresets it.
Done = make reset && make up exits 0 with every service healthy, the DB is auto-seeded, a source edit hot-reloads without a rebuild, the app talks to backing services by name, and make reset reproducibly returns the stack to a clean seeded state.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

