home / skills / aidotnet / moyucode / docker-compose

docker-compose skill

/skills/community/docker-compose

This skill helps you create production-ready docker-compose configurations for multi-container apps with health checks, networking, and overrides.

npx playbooks add skill aidotnet/moyucode --skill docker-compose

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
2.7 KB
---
name: docker-compose
description: 创建和管理多容器应用的Docker Compose配置,包含生产级设置、健康检查和网络配置。
metadata:
  short-description: 生成Docker Compose配置
---

# Docker Compose Skill

## Description
Create Docker Compose configurations for multi-container applications with best practices.

## Trigger
- `/docker` command
- User requests Docker configuration
- User needs containerization help

## Prompt

You are a Docker expert that creates production-ready container configurations.

### Web Application Stack

```yaml
version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=production
      - DATABASE_URL=postgresql://user:pass@db:5432/myapp
      - REDIS_URL=redis://redis:6379
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_started
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
      interval: 30s
      timeout: 10s
      retries: 3
    restart: unless-stopped
    networks:
      - app-network

  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: user
      POSTGRES_PASSWORD: pass
      POSTGRES_DB: myapp
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U user -d myapp"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - app-network

  redis:
    image: redis:7-alpine
    command: redis-server --appendonly yes
    volumes:
      - redis_data:/data
    networks:
      - app-network

  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - ./certs:/etc/nginx/certs:ro
    depends_on:
      - app
    networks:
      - app-network

volumes:
  postgres_data:
  redis_data:

networks:
  app-network:
    driver: bridge
```

### Development Override

```yaml
# docker-compose.override.yml
version: '3.8'

services:
  app:
    build:
      target: development
    volumes:
      - .:/app
      - /app/node_modules
    environment:
      - NODE_ENV=development
    command: npm run dev

  db:
    ports:
      - "5432:5432"
```

### Multi-Stage Dockerfile

```dockerfile
# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production

# Production stage
FROM node:20-alpine AS production
WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY . .
USER node
EXPOSE 3000
CMD ["node", "dist/main.js"]
```

## Tags
`docker`, `containers`, `devops`, `infrastructure`, `orchestration`

## Compatibility
- Codex: ✅
- Claude Code: ✅

Overview

This skill generates production-ready Docker Compose configurations for multi-container applications, including networking, volumes, and service dependencies. It focuses on secure defaults, health checks, and environment setups to make deployments reliable and maintainable.

How this skill works

I produce complete docker-compose definitions and optional development overrides and multi-stage Dockerfiles tailored to your stack. Outputs include service healthchecks, restart policies, persistent volumes, bridge networks, and recommendations for environment variables, port mappings, and volume mounts.

When to use it

  • You need a production-grade Compose file for a web app with database and cache services.
  • You want a development override that mounts source code and uses dev commands.
  • You need multi-stage Dockerfiles to minimize image size and separate build/runtime.
  • You want to add health checks, restart policies, or service dependency ordering.
  • You need a starting Compose template for Nginx reverse proxy, TLS, and app routing.

Best practices

  • Use healthcheck and depends_on with service_healthy to ensure proper startup order.
  • Keep secrets out of compose files; use environment files or secret managers.
  • Use named volumes for persistent data and bind-mounts only in development.
  • Build multi-stage images to install dependencies in a builder stage and copy only artifacts to runtime.
  • Expose only required ports on production services; route traffic through a reverse proxy.
  • Set restart policies (e.g., unless-stopped) and resource limits where appropriate.

Example use cases

  • Create a compose stack for Node.js app + Postgres + Redis with healthchecks and volumes.
  • Generate a docker-compose.override.yml for local development with live reload and mounted code.
  • Add an Nginx service for TLS termination with mounted certs and custom config.
  • Produce a multi-stage Dockerfile that installs dependencies in a builder and runs as a non-root user.
  • Convert a single-container setup into a multi-service Compose configuration for staging or production.

FAQ

How do I keep database credentials secure?

Do not commit credentials in compose files. Use .env files excluded from source control, Docker secrets, or an external secrets manager.

When should I use depends_on vs healthcheck?

depends_on handles startup ordering but not readiness; combine it with healthcheck and service_healthy to wait for a service to be ready.