用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tools-only/X-Skills --skill dockerfile-generate命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Index of Build Systems Skills
Coordination patterns for distributed dataflow systems including barriers, epochs, and distributed snapshots
Windowing, sessionization, time-series aggregation, and late data handling for streaming systems
基于 SOC 职业分类
正在显示 SKILL.md
| name | dockerfile-generate |
| description | Generate optimized Dockerfile with multi-stage builds |
| shortcut | dg |
| category | devops |
| difficulty | beginner |
| estimated_time | 1 minute |
Automatically generates production-ready Dockerfiles with multi-stage builds, security hardening, and optimizations based on your project type.
/docker-compose-create instead)You are a Docker expert. When user runs /dockerfile-generate or /dg:
Detect project type:
# Check for language-specific files
package.json → Node.js
requirements.txt → Python
go.mod → Go
pom.xml → Java
Gemfile → Ruby
Cargo.toml → Rust
Ask key questions:
Generate optimized Dockerfile:
Create .dockerignore:
Provide build instructions:
# Dockerfile
[Complete optimized Dockerfile with comments]
# .dockerignore
[Complete file]
## Build Instructions
### Build:
```bash
docker build -t app-name:latest .
docker run -p 3000:3000 app-name:latest
docker images app-name:latest
## Examples
### Example 1: Node.js Express API
**User:** `/dg` (in Node.js project with package.json)
**Questions:**
- Entry point? → `src/index.js`
- Port? → `3000`
- Build step? → `Yes, TypeScript compilation`
- Health endpoint? → `/health`
**Output:**
```dockerfile
# Multi-stage Dockerfile for Node.js Express API
# Optimized for production: ~150MB final image
# Stage 1: Build environment
FROM node:20-alpine AS builder
WORKDIR /app
# Copy dependency files first (better caching)
COPY package*.json ./
# Install all dependencies (including dev deps for build)
RUN npm ci
# Copy source code
COPY . .
# Build TypeScript
RUN npm run build
# Stage 2: Production environment
FROM node:20-alpine AS production
# Create non-root user
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install production dependencies only
RUN npm ci --only=production && \
npm cache clean --force
# Copy built application from builder
COPY --from=builder --chown=nodejs:nodejs /app/dist ./dist
# Switch to non-root user
USER nodejs
# Expose port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
# Start application
CMD ["node", "dist/index.js"]
# .dockerignore
node_modules
dist
build
npm-debug.log
.env
.env.local
.git
.gitignore
*.md
.vscode
.idea
.DS_Store
coverage
.nyc_output
User: /dg (in Python project with requirements.txt)
Questions:
app.py8000No/api/healthOutput:
# Optimized Dockerfile for Python Flask API
# Production-ready: ~120MB final image
FROM python:3.11-slim AS production
# Prevent Python from buffering stdout/stderr
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
# Create non-root user
RUN groupadd -g 1001 appuser && \
useradd -r -u 1001 -g appuser appuser
WORKDIR /app
# Install system dependencies (if needed)
# RUN apt-get update && apt-get install -y --no-install-recommends \
# gcc \
# && rm -rf /var/lib/apt/lists/*
# Copy requirements first (better caching)
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY --chown=appuser:appuser . .
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/api/health').read()"
# Start application
CMD ["python", "app.py"]
# .dockerignore
__pycache__
*.pyc
*.pyo
*.pyd
.Python
env
venv
.venv
.env
.git
.gitignore
*.md
.vscode
.pytest_cache
.coverage
htmlcov
User: /dg (in Go project with go.mod)
Questions:
cmd/api/main.go8080Yes, Go compilation/healthOutput:
# Multi-stage Dockerfile for Go API
# Produces tiny static binary: ~10-15MB
# Stage 1: Build environment
FROM golang:1.21-alpine AS builder
WORKDIR /app
# Copy go mod files first (better caching)
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Build static binary
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o api ./cmd/api
# Stage 2: Minimal runtime
FROM alpine:latest
# Install ca-certificates for HTTPS
RUN apk --no-cache add ca-certificates
# Create non-root user
RUN addgroup -g 1001 -S appuser && \
adduser -S appuser -u 1001 -G appuser
WORKDIR /app
# Copy binary from builder
COPY --from=builder --chown=appuser:appuser /app/api .
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
# Start application
CMD ["./api"]
# .dockerignore
.git
.gitignore
*.md
.vscode
.idea
vendor
*.exe
*.exe~
*.dll
*.so
*.dylib
*.test
*.out
Multi-stage builds reduce size by 80-90% Always use .dockerignore (faster builds) Non-root user is critical for security Health checks enable container orchestration Use specific version tags (not :latest)
Issue: Build fails at npm install
→ Ensure package-lock.json is present (use npm ci not npm install)
Issue: Image is still large (>500MB) → Check for unnecessary files in .dockerignore → Verify using alpine/slim base image → Ensure dev dependencies excluded in production stage
Issue: Permission denied errors
→ Make sure files are chowned to non-root user in COPY commands
→ Example: COPY --chown=nodejs:nodejs
Issue: Health check failing → Verify health endpoint is accessible inside container → Check port mapping is correct → Ensure application starts before first health check (use --start-period)