返回技能列表

setup-compose-stack

pjt222
更新于 Yesterday
7 次查看
17
2
17
在 GitHub 上查看
apidata

关于

This Claude Skill generates Docker Compose configurations for common multi-service application patterns like web apps with databases, caches, and background workers. It handles orchestration details including networks, volumes, health checks, dependencies, and environment management. Use it to quickly set up reproducible development or deployment environments for interconnected services.

快速安装

Claude Code

推荐
主要方式
npx skills add pjt222/agent-almanac -a claude-code
插件命令备选方式
/plugin add https://github.com/pjt222/agent-almanac
Git 克隆备选方式
git 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 application stacks with databases, caches, and workers.

When to Use

  • Running a web app with a database and/or cache
  • Setting up a development environment with multiple services
  • Orchestrating background workers alongside an API
  • Reproducible multi-service environments across teams

Inputs

  • Required: Application service (language, port, entry point)
  • Required: Supporting services needed (database, cache, queue, etc.)
  • Optional: Development vs production configuration
  • Optional: Existing Dockerfiles for custom services

Procedure

Step 1: Define 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:

Got: docker compose up starts all services with the app waiting for a healthy database.

Step 2: Add Health Checks

Health checks enable depends_on with 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: Configure Networks

services:
  app:
    networks:
      - frontend
      - backend

  postgres:
    networks:
      - backend

  nginx:
    networks:
      - frontend
    ports:
      - "80:80"

networks:
  frontend:
    driver: bridge
  backend:
    driver: bridge

This isolates the database from direct external access while the app bridges both networks.

Step 4: Manage Environment Variables

Create .env file (git-ignored):

POSTGRES_PASSWORD=secure_password_here
APP_SECRET=your_secret_key

Reference in compose:

services:
  postgres:
    environment:
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
  app:
    env_file:
      - .env

Create .env.example (committed to git):

POSTGRES_PASSWORD=changeme
APP_SECRET=changeme

Step 5: Add 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: Use Profiles for Optional Services

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: Create Override for Development

docker-compose.override.yml is 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 and 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

Got: All services start, health checks pass, app connects to database and cache.

If fail: Check docker compose logs <service>. Common issues: port conflicts, missing environment variables, health check timeouts.

Validation

  • docker compose up starts all services without errors
  • Health checks pass for database and cache
  • Application connects to all dependent services
  • Named volumes persist data across restarts
  • .env is git-ignored; .env.example is committed
  • docker compose down cleanly stops everything
  • Profiles separate dev tools from production services

Pitfalls

  • No health checks: depends_on without condition: service_healthy only waits for container start, not readiness.
  • Hardcoded passwords in compose: Use .env files or Docker secrets. Never commit passwords.
  • Volume mount overwrites: Mounting .:/app overwrites node_modules built in the image. Use an anonymous volume: /app/node_modules.
  • Port conflicts: Check docker compose ps and lsof -i :<port> for conflicts.
  • version: key: Compose V2 ignores the version: key. Omit it for modern setups.
  • WSL path issues: Use /mnt/c/... paths when mounting Windows directories from WSL.

Related Skills

  • setup-docker-compose - R-specific Docker Compose configurations
  • create-dockerfile - write the Dockerfile that compose references
  • create-multistage-dockerfile - build optimized images for the stack
  • configure-nginx - add an Nginx reverse proxy to the stack

GitHub 仓库

pjt222/agent-almanac
路径: i18n/caveman-lite/skills/setup-compose-stack
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

相关推荐技能

content-collections

Content Collections 是一个 TypeScript 优先的构建工具,可将本地 Markdown/MDX 文件转换为类型安全的数据集合。它专为构建博客、文档站和内容密集型 Vite+React 应用而设计,提供基于 Zod 的自动模式验证。该工具涵盖从 Vite 插件配置、MDX 编译到生产环境部署的完整工作流。

查看技能

polymarket

这个Claude Skill为开发者提供完整的Polymarket预测市场开发支持,涵盖API调用、交易执行和市场数据分析。关键特性包括实时WebSocket数据流,可监控实时交易、订单和市场动态。开发者可用它构建预测市场应用、实施交易策略并集成实时市场预测功能。

查看技能

creating-opencode-plugins

该Skill帮助开发者创建OpenCode插件,用于接入命令、文件、LSP等25+种事件。它提供了插件结构、事件API规范和JavaScript/TypeScript实现模式,适合需要拦截操作、扩展功能或自定义事件处理的场景。开发者可通过它快速构建响应式模块来增强OpenCode AI助手的能力。

查看技能

sglang

SGLang是一个专为LLM设计的高性能推理框架,特别适用于需要结构化输出的场景。它通过RadixAttention前缀缓存技术,在处理JSON、正则表达式、工具调用等具有重复前缀的复杂工作流时,能实现极速生成。如果你正在构建智能体或多轮对话系统,并追求远超vLLM的推理性能,SGLang是理想选择。

查看技能