用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tools-only/X-Skills --skill docker-compose-create命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | docker-compose-create |
| description | Generate docker-compose.yml for multi-service applications |
| shortcut | dcc |
| category | devops |
| difficulty | intermediate |
| estimated_time | 2 minutes |
Creates production-ready docker-compose.yml files for multi-service applications with proper networking, volumes, health checks, and environment management.
/dockerfile-generate instead)You are a Docker Compose expert. When user runs /docker-compose-create or /dcc:
Identify services: Ask user to specify:
Determine requirements:
Generate docker-compose.yml:
Create .env template:
Provide usage instructions:
# docker-compose.yml
[Complete compose file with comments]
# .env.example
[Environment variables template]
## Usage
### Start all services:
```bash
docker-compose up -d
docker-compose logs -f [service-name]
docker-compose down
docker-compose up -d --build
## Examples
### Example 1: Node.js API + PostgreSQL + Redis
**User:** `/dcc`
**Services specified:**
- Node.js API (port 3000)
- PostgreSQL database
- Redis cache
**Output:**
```yaml
# docker-compose.yml
version: '3.8'
services:
# Node.js API service
api:
build:
context: .
dockerfile: Dockerfile
container_name: api
restart: unless-stopped
ports:
- "3000:3000"
environment:
- NODE_ENV=production
- DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}
- REDIS_URL=redis://redis:6379
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
networks:
- app-network
volumes:
- ./logs:/app/logs
# PostgreSQL database
db:
image: postgres:15-alpine
container_name: postgres-db
restart: unless-stopped
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- postgres-data:/var/lib/postgresql/data
networks:
- app-network
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"]
interval: 10s
timeout: 5s
retries: 5
# Redis cache
redis:
image: redis:7-alpine
container_name: redis-cache
restart: unless-stopped
command: redis-server --requirepass ${REDIS_PASSWORD}
volumes:
- redis-data:/data
networks:
- app-network
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 3s
retries: 5
# Named volumes for data persistence
volumes:
postgres-data:
driver: local
redis-data:
driver: local
# Custom network for service isolation
networks:
app-network:
driver: bridge
# .env.example
# Copy this file to .env and fill in your values
# PostgreSQL Configuration
POSTGRES_DB=myapp
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your_secure_password_here
# Redis Configuration
REDIS_PASSWORD=your_redis_password_here
# Application Configuration
NODE_ENV=production
User: /dcc
Services specified:
Output:
# docker-compose.yml
version: '3.8'
services:
# React frontend
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
container_name: frontend
restart: unless-stopped
ports:
- "80:80"
environment:
- REACT_APP_API_URL=http://localhost:5000
depends_on:
- backend
networks:
- app-network
# Express backend
backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: backend
restart: unless-stopped
ports:
- "5000:5000"
environment:
- NODE_ENV=production
- MONGODB_URI=mongodb://${MONGO_USER}:${MONGO_PASSWORD}@mongodb:27017/${MONGO_DB}?authSource=admin
- JWT_SECRET=${JWT_SECRET}
depends_on:
mongodb:
condition: service_healthy
# .env.example
# MongoDB Configuration
MONGO_USER=admin
MONGO_PASSWORD=your_secure_password_here
MONGO_DB=myapp
# Backend Configuration
JWT_SECRET=your_jwt_secret_here
NODE_ENV=production
# Frontend Configuration
REACT_APP_API_URL=http://localhost:5000
User: /dcc
Services specified:
Output:
# docker-compose.yml
version: '3.8'
services:
# Nginx API Gateway
gateway:
image: nginx:alpine
container_name: api-gateway
restart: unless-stopped
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- user-service
- product-service
- order-service
networks:
- app-network
# User Service
user-service:
build:
context: ./services/user-service
dockerfile: Dockerfile
container_name: user-service
restart: unless-stopped
environment:
- DATABASE_URL=postgresql://postgres:${POSTGRES_PASSWORD}@db:5432/users
- SERVICE_PORT=3001
depends_on:
db:
condition: service_healthy
networks:
- app-network
# Product Service
[, ]
# .env.example
# Database Configuration
POSTGRES_PASSWORD=your_secure_password_here
Use health checks to ensure services start in correct order Named volumes persist data across container restarts Custom networks isolate services from other containers Always use .env files (never commit secrets) Service names become DNS hostnames (e.g., db, redis)
PostgreSQL:
db:
image: postgres:15-alpine
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- postgres-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"]
interval: 10s
timeout: 5s
retries: 5
MySQL:
db:
image: mysql:8
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
volumes:
- mysql-data:/var/lib/mysql
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 5
Redis:
redis:
image: redis:7-alpine
command: redis-server --requirepass ${REDIS_PASSWORD}
volumes:
- redis-data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 3s
retries: 5
Issue: Services can't communicate
→ Ensure all services are on same network
→ Use service names as hostnames (e.g., http://backend:5000)
Issue: Data lost on restart → Verify named volumes are defined → Check volume mount paths match service defaults
Issue: Service starts before dependency ready
→ Add health checks to dependencies
→ Use condition: service_healthy in depends_on
Issue: Environment variables not loading → Create .env file from .env.example → Ensure .env is in same directory as docker-compose.yml
基于 SOC 职业分类