Multi Stage Dockerfile
Use when creating or reviewing reproducible, minimal, and secure multi-stage Dockerfiles for an application or service.
Install
npx skills add sandbaseai/workbuddy-skill --skill multi-stage-dockerfilegit clone --depth 1 https://github.com/sandbaseai/workbuddy-skill.git /tmp/workbuddy-skill
mkdir -p ~/.claude/skills
cp -r /tmp/workbuddy-skill/skills/multi-stage-dockerfile ~/.claude/skills/multi-stage-dockerfilePersonal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.
From the SKILL.md
# 多阶段 Dockerfile
设计可复现、体积受控、最小权限的容器镜像。先明确运行时、架构、端口、数据目录、健康语义、来源和发布环境,再把依赖、构建、测试与运行时分开;Dockerfile 是构建输入,不应携带凭据或隐含生产变更。
## 使用边界
- 开始前确认应用入口、语言/框架版本、CPU/OS 架构、构建器、基础镜像来源、registry、镜像 owner、扫描策略、运行 UID/GID、网络和数据持久化。
- 默认在隔离环境执行 lint、构建、测试和镜像检查;不得拉取不可信镜像、挂载宿主敏感目录、使用 privileged、访问生产 registry 或部署新镜像。
- 不把 secret 放入 `ARG`、`ENV`、Dockerfile、镜像层、构建日志或标签;需要凭据时使用 BuildKit secret/SSH mount,并确认最终层、history 和 provenance 不含秘密。
- 镜像构建成功不等于应用安全;记录 observed、derived、unknown,并把 registry 推送、部署、回滚和运行时权限变更交给明确授权流程。
## 阶段结构
按依赖 → 构建 → 测试 → 运行时组织阶段,并使用有意义的 `AS` 名称。构建阶段可包含编译器、包管理器和测试工具;runtime 只复制必要产物、证书、配置模板和非敏感资源,不能整段复制源码、缓存、`.git`、测试数据或构建工具。
```dockerfile
FROM python:3.12.4-slim-bookworm AS builder
WORKDIR /build
COPY pyproject.toml uv.lock ./
RUN --mount=type=cache,target=/root/.cache \
--mount=type=secret,id=private_index \
python -m pip install --no-cache-dir --prefix=/opt/app -r requirements.txt
COPY src ./src
RUN python -m compileall -q src
FROM gcr.io/distroless/python3-debian12:nonroot AS runtime
WORKDIR /app
COPY --from=builder /opt/app /opt/app
COPY --from=builder /build/src /app/src
USER nonroot:nonroot
ENV PYTHONPATH=/app:/opt/app
ENTRYPOINT ["python", "-m", "src.main"]
```
示例中的版本、依赖文件、入口和镜像必须替换为项目实际契约;不要因为示例使用 distroless/Alpine 就忽略兼容性、C 库、证书、时区或调试需求。
## 基础镜像与可复现性
- 优先选择官方、维护中的最小镜像,并固定 digest;至少固定完整版本 tag,记录来源、架构、发布时间和漏洞基线。
- 明确 glibc/musl、CA certificates、时区、字体、动态库、用户数据库和 DNS 行为;运行时缺失依赖要在隔离 smoke test 中暴露。
- 锁定直接和传递依赖、包源、校验和及构建工具版本;避免浮动 tag、未认证第三方 registry 和构建时在线解析未锁定版本。Details
- Skill name
multi-stage-dockerfile- Repository
- sandbaseai/workbuddy-skill
- Path
skills/multi-stage-dockerfile/SKILL.md- License
- MIT
- Repo updated
- 8 September 2026
FAQ
What does the Multi Stage Dockerfile skill do?
Use when creating or reviewing reproducible, minimal, and secure multi-stage Dockerfiles for an application or service.
How do I install the Multi Stage Dockerfile skill?
skills CLI (Claude Code, Cursor, Codex and more): npx skills add sandbaseai/workbuddy-skill --skill multi-stage-dockerfile. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.
Is Multi Stage Dockerfile popular?
It lives in sandbaseai/workbuddy-skill, which has 9 GitHub stars and 3 forks.
Related skills
Access Control Security Best Practices
9sandbaseai/workbuddy-skill
Design, review, implement, and verify least-privilege access controls across users, services, tenants, resources, and administrative workflows.
Accessibility Review
9sandbaseai/workbuddy-skill
Use when reviewing a web interface or interaction for semantic, keyboard, focus, screen-reader, ARIA, and contrast accessibility risks.
Acquire Codebase Knowledge
9sandbaseai/workbuddy-skill
Use when the user asks to map, document, or onboard into an existing codebase and needs evidence-backed architecture, structure, conventions, integrations, testing, and concerns documentation.
Performance Engineering
9sandbaseai/workbuddy-skill
Use when validating capacity, diagnosing latency or resource bottlenecks, profiling CPU/memory/I/O, optimizing responsiveness, or preventing performance regressions; establish a comparable baseline before changing code or infrastructure.
Monitoring Observability
9sandbaseai/workbuddy-skill
Use when defining service objectives, instrumenting metrics, logs, or traces, designing dashboards and alerts, or auditing whether telemetry supports reliable diagnosis; ground every signal in a user journey and an operational response.
Privacy Engineering
9sandbaseai/workbuddy-skill
Use when implementing or auditing privacy controls in products, infrastructure, analytics, or data flows; translate privacy principles into classification, minimization, consent, subject-rights, retention, vendor, and deletion evidence.
Browse the most popular Claude skills, all devops & cloud skills, or write your own with the skills generator.