Agent Skillsnixopus/nixopus › compose-setup

compose-setup

GitHub

根据代码依赖自动检测数据库、缓存或消息中间件,生成包含多服务依赖和配置的多容器 Docker Compose 文件。

api/skills/compose-setup/SKILL.md nixopus/nixopus

Trigger Scenarios

应用需要数据库、缓存或消息代理 多服务独立部署架构 Monorepo 多 Dockerfile 结构

Install

npx skills add nixopus/nixopus --skill compose-setup -g -y
More Options

Non-standard path

npx skills add https://github.com/nixopus/nixopus/tree/master/api/skills/compose-setup -g -y

Use without installing

npx skills use nixopus/nixopus@compose-setup

指定 Agent (Claude Code)

npx skills add nixopus/nixopus --skill compose-setup -a claude-code -g -y

安装 repo 全部 skill

npx skills add nixopus/nixopus --all -g -y

预览 repo 内 skill

npx skills add nixopus/nixopus --list

SKILL.md

Frontmatter
{
    "name": "compose-setup",
    "metadata": {
        "version": "1.0"
    },
    "description": "Generate docker-compose.yml for multi-service setups including databases, caches, and service dependencies. Use when the app needs a database, cache, message broker, or has multiple independently deployable services."
}

Docker Compose Setup

Generate docker-compose.yml when the application needs multiple services (app + database, app + cache, monorepo services).

When to use docker-compose

  • App requires a database (PostgreSQL, MySQL, MongoDB, Redis)
  • App has multiple independently deployable services
  • App needs a message broker (RabbitMQ, Kafka)
  • Monorepo with multiple Dockerfile entries

Single-service apps with no external dependencies should use a standalone Dockerfile.

Detection from source code

Look for these signals to determine required services:

Pattern in code or config Service needed
DATABASE_URL=postgres:// or pg dependency PostgreSQL
DATABASE_URL=mysql:// or mysql2 dependency MySQL
MONGODB_URI or mongoose dependency MongoDB
REDIS_URL or ioredis/redis dependency Redis
RABBITMQ_URL or amqplib dependency RabbitMQ
KAFKA_BROKERS Kafka
.env.example listing service URLs Parse each URL for service type

Compose template structure

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "${PORT:-3000}:3000"
    environment:
      - NODE_ENV=production
      - DATABASE_URL=postgresql://postgres:postgres@db:5432/app
    depends_on:
      db:
        condition: service_healthy
    restart: unless-stopped

  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: app
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 3s
      retries: 5
    restart: unless-stopped

volumes:
  pgdata:

Common service blocks

PostgreSQL

db:
  image: postgres:16-alpine
  environment:
    POSTGRES_USER: postgres
    POSTGRES_PASSWORD: postgres
    POSTGRES_DB: app
  volumes:
    - pgdata:/var/lib/postgresql/data
  healthcheck:
    test: ["CMD-SHELL", "pg_isready -U postgres"]
    interval: 5s
    timeout: 3s
    retries: 5

MySQL

db:
  image: mysql:8.0
  environment:
    MYSQL_ROOT_PASSWORD: root
    MYSQL_DATABASE: app
    MYSQL_USER: app
    MYSQL_PASSWORD: app
  volumes:
    - mysqldata:/var/lib/mysql
  healthcheck:
    test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
    interval: 5s
    timeout: 3s
    retries: 5

MongoDB

mongo:
  image: mongo:7
  environment:
    MONGO_INITDB_ROOT_USERNAME: root
    MONGO_INITDB_ROOT_PASSWORD: root
  volumes:
    - mongodata:/data/db
  healthcheck:
    test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
    interval: 5s
    timeout: 3s
    retries: 5

Redis

redis:
  image: redis:7-alpine
  command: redis-server --appendonly yes
  volumes:
    - redisdata:/data
  healthcheck:
    test: ["CMD", "redis-cli", "ping"]
    interval: 5s
    timeout: 3s
    retries: 5

Monorepo services

For monorepos with multiple services under apps/ or services/:

services:
  api:
    build:
      context: .
      dockerfile: apps/api/Dockerfile
    ports:
      - "3001:3001"
    depends_on:
      db:
        condition: service_healthy

  web:
    build:
      context: .
      dockerfile: apps/web/Dockerfile
    ports:
      - "3000:3000"
    depends_on:
      - api

Set build context to the repo root so shared packages are accessible. Each Dockerfile handles its own COPY paths.

Rules

  • Always use named volumes for persistent data
  • Always add healthchecks for databases and caches
  • Use depends_on with condition: service_healthy so the app waits for healthy dependencies
  • Use restart: unless-stopped for all services
  • Reference env vars from .env.example when available
  • Default to Alpine/slim images for smaller footprint
  • Pin image versions (e.g. postgres:16-alpine, not postgres:latest)

Related Skills

  • env-detection — Detect required service connection URLs (DATABASE_URL, REDIS_URL, etc.) to determine which services to include
  • dockerfile-generation — Generate the Dockerfile for each service in the compose file

Version History

  • cf05d97 Current 2026-08-20 14:51

Same Skill Collection

api/skills/api-catalog/SKILL.md
api/skills/caddyfile-generation/SKILL.md
api/skills/container-resource-tuning/SKILL.md
api/skills/cpp-deploy/SKILL.md
api/skills/database-migration/SKILL.md
api/skills/deno-deploy/SKILL.md
api/skills/deploy-delegation/SKILL.md
api/skills/deploy-flow/SKILL.md
api/skills/deployment-analysis/SKILL.md
api/skills/diagnostic-workflow/SKILL.md
api/skills/dockerfile-generation/SKILL.md
api/skills/dockerignore-generation/SKILL.md
api/skills/domain-attachment/SKILL.md
api/skills/domain-tls-routing/SKILL.md
api/skills/dotnet-deploy/SKILL.md
api/skills/elixir-deploy/SKILL.md
api/skills/failure-diagnosis/SKILL.md
api/skills/github-onboarding/SKILL.md
api/skills/github-workflow/SKILL.md
api/skills/gleam-deploy/SKILL.md
api/skills/go-deploy/SKILL.md
api/skills/incident-response/SKILL.md
api/skills/java-deploy/SKILL.md
api/skills/machine-ops/SKILL.md
api/skills/mcp-integrations/SKILL.md
api/skills/monorepo-strategy/SKILL.md
api/skills/nixopus-docs/SKILL.md
api/skills/node-deploy/SKILL.md
api/skills/onboarding/SKILL.md
api/skills/php-deploy/SKILL.md
api/skills/post-deploy-verification/SKILL.md
api/skills/pre-deploy-checklist/SKILL.md
api/skills/python-deploy/SKILL.md
api/skills/rollback-strategy/SKILL.md
api/skills/ruby-deploy/SKILL.md
api/skills/rust-deploy/SKILL.md
api/skills/self-heal/SKILL.md
api/skills/shell-deploy/SKILL.md
api/skills/static-deploy/SKILL.md

Metadata

Files
0
Version
cf05d97
Hash
d419dc4d
Indexed
2026-08-20 14:51

- 위키
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-30 05:16
浙ICP备14020137号-1 $방문자$