setup-compose-stack
关于
This skill generates Docker Compose configurations for common multi-service application patterns like web apps with databases, caches, and background workers. It implements production-ready features including named volumes, health checks, dependency management, and environment variable handling. Developers should use it to quickly create reproducible containerized environments for development, testing, or deployment scenarios.
快速安装
Claude Code
推荐npx skills add pjt222/agent-almanac -a claude-code/plugin add https://github.com/pjt222/agent-almanacgit clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/setup-compose-stack在 Claude Code 中复制并粘贴此命令以安装该技能
技能文档
Set Up Compose Stack
Configure Docker Compose for multi-service stacks w/ DBs, caches, workers.
Use When
- Web app + DB|cache
- Dev env w/ multi services
- Bg workers + API
- Reproducible multi-service envs
In
- Required: App service (lang, port, entry)
- Required: Supporting services (DB, cache, queue)
- Optional: Dev vs prod config
- Optional: Existing Dockerfiles
Do
Step 1: Core Stack
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
environment:
DATABASE_URL: postgres://appuser:apppass@postgres:5432/appdb
REDIS_URL: redis://redis:6379
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_started
restart: unless-stopped
postgres:
image: postgres:16
environment:
POSTGRES_DB: appdb
POSTGRES_USER: appuser
POSTGRES_PASSWORD: apppass
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U appuser -d appdb"]
interval: 5s
timeout: 5s
retries: 5
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
- redisdata:/data
volumes:
pgdata:
redisdata:
→ docker compose up starts all, app waits for healthy DB.
Step 2: Health Checks
Enable depends_on w/ condition: service_healthy:
services:
postgres:
healthcheck:
test: ["CMD-SHELL", "pg_isready -U appuser -d appdb"]
interval: 5s
timeout: 5s
retries: 5
redis:
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 5
app:
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 10s
timeout: 5s
retries: 3
start_period: 10s
Step 3: Networks
services:
app:
networks:
- frontend
- backend
postgres:
networks:
- backend
nginx:
networks:
- frontend
ports:
- "80:80"
networks:
frontend:
driver: bridge
backend:
driver: bridge
Isolates DB from external; app bridges both.
Step 4: Env Vars
.env (git-ignored):
POSTGRES_PASSWORD=secure_password_here
APP_SECRET=your_secret_key
Reference:
services:
postgres:
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
app:
env_file:
- .env
.env.example (committed):
POSTGRES_PASSWORD=changeme
APP_SECRET=changeme
Step 5: Worker Services
services:
worker:
build:
context: .
dockerfile: Dockerfile
command: ["node", "src/worker.js"]
environment:
DATABASE_URL: postgres://appuser:apppass@postgres:5432/appdb
REDIS_URL: redis://redis:6379
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_started
restart: unless-stopped
deploy:
replicas: 2
Step 6: Profiles for Optional
services:
app:
# always starts
build: .
mailhog:
image: mailhog/mailhog
ports:
- "8025:8025"
profiles:
- dev
adminer:
image: adminer
ports:
- "8080:8080"
profiles:
- dev
# Start core services only
docker compose up
# Start with dev tools
docker compose --profile dev up
Step 7: Override for Dev
docker-compose.override.yml auto-merged:
services:
app:
build:
target: dev
volumes:
- .:/app
- /app/node_modules
environment:
NODE_ENV: development
DEBUG: "app:*"
command: ["npm", "run", "dev"]
Step 8: Build + Run
# Build all images
docker compose build
# Start in background
docker compose up -d
# View logs
docker compose logs -f app
# Check service status
docker compose ps
# Stop and remove
docker compose down
# Stop and remove volumes (full reset)
docker compose down -v
→ All services start, health checks pass, app connects DB+cache.
If err: docker compose logs <service>. Common: port conflicts, missing env vars, health check timeouts.
Check
-
docker compose upstarts w/o errs - Health checks pass DB+cache
- App connects all deps
- Named volumes persist across restarts
-
.envgit-ignored;.env.examplecommitted -
docker compose downcleanly stops - Profiles separate dev from prod
Traps
- No health checks:
depends_onw/ocondition: service_healthyonly waits for container start, not ready. - Hardcoded pwds:
.env|Docker secrets. Never commit pwds. - Volume mount overwrites: Mounting
.:/appoverwrites image'snode_modules. Anonymous volume:/app/node_modules. - Port conflicts:
docker compose ps+lsof -i :<port>. version:key: Compose V2 ignores. Omit for modern.- WSL path issues:
/mnt/c/...for Windows dirs from WSL.
→
setup-docker-compose— R-specific configscreate-dockerfile— write Dockerfilecreate-multistage-dockerfile— optimized imagesconfigure-nginx— add Nginx reverse proxy
GitHub 仓库
相关推荐技能
railway-docs
文档Railway Docs Skill可实时获取最新的Railway官方文档,确保回答的准确性。当开发者询问Railway功能特性、工作原理或分享docs.railway.com链接时,应优先使用此技能。它通过专门的LLM优化文档源提供最新信息,避免依赖过时记忆来回答技术问题。
n8n-code-python
文档该Skill为在n8n平台的Python代码节点中编写代码提供专家指导,特别适用于需要使用_input/_json/_node语法、Python标准库或了解n8n中Python限制的场景。它强调JavaScript应作为首选方案,仅当需要特定Python功能或对Python语法更熟悉时才使用Python。Skill提供了快速入门模板和关键注意事项,帮助开发者在n8n中高效编写Python代码。
archon
文档Archon Skill为开发者提供了基于RAG的语义搜索和项目任务管理功能,可通过REST API访问知识库。它支持文档搜索、网站爬取、文件上传和版本控制,适用于技术文档查询和项目管理场景。首次使用时需要配置Archon主机地址,建议在处理外部文档时优先使用该Skill。
n8n-code-javascript
文档这个Skill为n8n工作流中的JavaScript代码节点提供专业指导,涵盖数据处理、HTTP请求和日期操作等核心场景。它详细解释了如何正确使用n8n特有的`$input`/`$json`语法、`$helpers`工具以及DateTime对象,并包含关键的错误排查和模式选择建议。开发者通过该Skill能快速掌握Code节点的正确返回格式、数据访问方法和常见陷阱解决方案。
