Back to Skills

setup-compose-stack

pjt222
Updated Yesterday
5 views
17
2
17
View on GitHub
Metaapidata

About

This Claude Skill generates Docker Compose configurations for common multi-service application stacks like web apps with databases, caches, and workers. It handles orchestration elements including named volumes, networks, health checks, and environment management. Use it when setting up development environments or creating reproducible multi-service deployments across teams.

Quick Install

Claude Code

Recommended
Primary
npx skills add pjt222/agent-almanac -a claude-code
Plugin CommandAlternative
/plugin add https://github.com/pjt222/agent-almanac
Git CloneAlternative
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/setup-compose-stack

Copy and paste this command in Claude Code to install this skill

Documentation

設 Compose 之棧

為多服應用之棧配 Docker Compose,附庫、緩、工。

用時

  • 行網應附庫與/或緩乃用
  • 設多服之開發境乃用
  • 並 API 與後台工乃用
  • 跨團需可重之多服境乃用

  • 必要:應之服(語、端口、入點)
  • 必要:所需之輔服(庫、緩、隊等)
  • 可選:開發 vs 生產之配
  • 可選:自定服之既 Dockerfile

第一步:定核之棧

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 啟諸服,應俟健庫。

第二步:增健察

健察使 depends_on 可用 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

第三步:配網

services:
  app:
    networks:
      - frontend
      - backend

  postgres:
    networks:
      - backend

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

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

此隔庫於外直訪,而應橋二網。

第四步:管環境變

.env 文件(git-ignored):

POSTGRES_PASSWORD=secure_password_here
APP_SECRET=your_secret_key

於 compose 引:

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

.env.example(提交於 git):

POSTGRES_PASSWORD=changeme
APP_SECRET=changeme

第五步:增工服

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

第六步:以 profile 為選服

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

第七步:為開發立 override

docker-compose.override.yml 自動合並:

services:
  app:
    build:
      target: dev
    volumes:
      - .:/app
      - /app/node_modules
    environment:
      NODE_ENV: development
      DEBUG: "app:*"
    command: ["npm", "run", "dev"]

第八步:建而行

# 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

得:諸服啟,健察過,應連庫與緩。

敗則:察 docker compose logs <service>。常患:端口衝、缺環變、健察超時。

  • docker compose up 啟諸服而無誤
  • 庫與緩之健察過
  • 應連諸依服
  • 命名卷跨重啟存數
  • .env 入 git-ignore;.env.example 已提交
  • docker compose down 潔止諸物
  • profile 分開發器與生產服

  • 無健察depends_on 而無 condition: service_healthy 唯俟容啟,非俟備
  • 硬編密於 compose:用 .env 或 Docker secret。永勿提交密
  • 卷掛蓋:掛 .:/app 蓋鏡中所建之 node_modules。用匿之卷:/app/node_modules
  • 端口衝:察 docker compose pslsof -i :<port> 為衝
  • version::Compose V2 忽 version: 鍵。新設略之
  • WSL 徑之患:自 WSL 掛 Windows 目用 /mnt/c/...

  • setup-docker-compose — R 特之 Docker Compose 配
  • create-dockerfile — 寫 compose 所引之 Dockerfile
  • create-multistage-dockerfile — 為棧建優之像
  • configure-nginx — 加 Nginx 反向代理於棧

GitHub Repository

pjt222/agent-almanac
Path: i18n/wenyan/skills/setup-compose-stack
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

Related Skills

content-collections

Meta

This skill provides a production-tested setup for Content Collections, a TypeScript-first tool that transforms Markdown/MDX files into type-safe data collections with Zod validation. Use it when building blogs, documentation sites, or content-heavy Vite + React applications to ensure type safety and automatic content validation. It covers everything from Vite plugin configuration and MDX compilation to deployment optimization and schema validation.

View skill

polymarket

Meta

This skill enables developers to build applications with the Polymarket prediction markets platform, including API integration for trading and market data. It also provides real-time data streaming via WebSocket to monitor live trades and market activity. Use it for implementing trading strategies or creating tools that process live market updates.

View skill

creating-opencode-plugins

Meta

This skill helps developers create OpenCode plugins that hook into 25+ event types like commands, files, and LSP operations. It provides the plugin structure, event API specifications, and implementation patterns for JavaScript/TypeScript modules. Use it when you need to intercept, monitor, or extend the OpenCode AI assistant's lifecycle with custom event-driven logic.

View skill

sglang

Meta

SGLang is a high-performance LLM serving framework that specializes in fast, structured generation for JSON, regex, and agentic workflows using its RadixAttention prefix caching. It delivers significantly faster inference, especially for tasks with repeated prefixes, making it ideal for complex, structured outputs and multi-turn conversations. Choose SGLang over alternatives like vLLM when you need constrained decoding or are building applications with extensive prefix sharing.

View skill