用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/mikailustuner/OmniRule --skill docker-patterns命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | docker-patterns |
| description | Docker: Multi-stage strategy, Security hardening approach, Volume strategy, When to use what. |
| triggers | {"filenames":["Dockerfile","docker-compose.yml","docker-compose.yaml",".dockerignore"],"keywords":["docker","container","image","compose","build","layer"]} |
| auto_load_when | Editing Dockerfile or docker-compose files |
| agent | devops-engineer |
| tools | ["Read","Write","Bash"] |
Focus: Security, optimization, patterns
When to use multi-stage:
├── Compilation needed (Node, Go, Python)
├── Different build and runtime environments
└── Want to minimize final image size
Stage pattern:
├── Build stage: dependencies, compile
├── Dependencies: only package.json
├── Source: full code
├── Output: compiled artifacts
└── Final: minimal runtime, copy artifacts only
Key principles:
Security layers:
├── Base image: specific version, not latest
├── User: non-root, created in Dockerfile
├── Filesystem: read-only where possible
├── Capabilities: drop all, add only needed
└── Secrets: never in image, use runtime
What to avoid:
├── Running as root
├── Latest tag (non-deterministic)
├── Secrets in ENV (exposed in layers)
└── Unnecessary packages in image
When to use volumes:
├── Database data (persist across restarts)
├── Build artifacts (share between stages)
└── Development (hot reload)
When NOT to use volumes:
├── Configuration (use env vars)
├── Secrets (use runtime injection)
└── Temporary data (tmpfs)
Type selection:
├── Named volumes: persistent data
├── Bind mounts: development, files
└── tmpfs: sensitive data in memory
When to use Compose:
├── Local development
├── Integration testing
├── Multiple services together
When to use directly:
├── Production deployment
├── Single service
└── Cloud deployment (Docker Swarm, K8s)
Compose patterns:
├── Override: base + local overrides
├── Profiles: enable/disable services
└── Depends on: startup order
How to minimize image:
├── Multi-stage builds
├── Minimal base image (alpine, slim)
├── Fewer layers (combine RUN)
├── .dockerignore (exclude build artifacts)
└── Build arguments for dynamic values
Layer caching:
├── Order: least frequent first, most frequent last
├── COPY package.json → RUN install → COPY code
└── Change at bottom = rebuild all below
When to add healthcheck:
├── Long-running services
├── Services that might hang
└── Services dependent by others
What to check:
├── HTTP endpoint: GET /health
├── Database: pg_isready
├── Custom: script that checks dependencies
└── TCP: port open
Frequency:
├── Start period: time to start up
├── Interval: how often to check
├── Timeout: how long to wait
└── Retries: how many failures to declare unhealthy
❌ RUN apt-get + app copy in one fat layer
✅ Multi-stage: builder stage installs deps, final stage copies artifact only
❌ Running as root inside containers
✅ USER node (or non-root) in Dockerfile
❌ Hardcoding secrets in ENV or ARG
✅ Inject secrets at runtime via --env-file or secrets manager
❌ :latest tag in production
✅ Pin exact image digest or semver tag
❌ No .dockerignore — sending node_modules to daemon
✅ .dockerignore: node_modules, .git, .env, dist
| Task | Pattern | Instruction |
|---|---|---|
| Small image | Alpine/distroless base | FROM node:20-alpine |
| Layer cache | Copy package.json first | COPY package*.json ./ |
| Build artifact | Multi-stage | FROM builder AS final |
| Non-root | USER directive | USER node |
| Health | HEALTHCHECK CMD | curl -f /health |
| Secrets | Runtime env | --env-file .env.prod |
| Image size check | docker build + inspect | docker image ls |