让 AI 写 Dockerfile,别再交”2019 年水平”的卷子了
让 AI 写 Dockerfile,别再交”2019 年水平”的卷子了
你有没有这种感觉——让 AI 写个 Dockerfile,拿回来一看:FROM ubuntu:latest、ARG TOKEN=... 明文塞进去、没有 USER 行、docker-compose 还是老写法……语法全对,但放到 2026 年就是过时产物。
SkillsMP 上有一个叫 docker 的 Skill,作者是 christian-deleon/dotfiles,专治这个问题。
它到底写了什么
这个 Skill 不是一个泛泛的”Docker 教程”,而是一套决策树 + 最佳实践清单,拆成了 6 个子文件:
- dockerfile.md(15.6KB)——多阶段构建、缓存挂载、build secrets、非 root 用户、安全加固
- base-images.md(10.6KB)——distroless、debian-slim、alpine 的 musl 陷阱、Chainguard 选型
- compose.md(18.3KB)——Compose v2 新语法(
compose.yaml取代docker-compose.yml、version:字段正式废弃)、watch 模式、profiles、healthcheck - build.md(14.5KB)——buildx / bake 多平台构建、CI 流水线模式
- supply-chain.md(12.6KB)——镜像签名(cosign)、SBOM、 Provenance、Trivy 扫描
总规模 65KB+,覆盖了从”写 Dockerfile”到”安全发布镜像”的完整闭环。
最值钱的是这个认知
Skill 开头有一段话我特别认同:
“The work isn’t writing a Dockerfile; it’s choosing the right base, caching the right layers, signing the result, and orchestrating the runtime in the right place.”
意思是——写 Dockerfile 本身不是重点,选对基础镜像、正确缓存层、签名验证、选择合适的运行时位置,这些才是 2026 年的及格线。
Skill 还专门列了一份”AI 常见失败清单”:FROM ubuntu:latest、分离的 apt-get update 层、:latest 生产标签、depends_on 配 sleep 30……这些都不是语法错误,但都是 2026 年的代码异味。
怎么用
在 Claude Code / Codex CLI 里输入:
npx skills add https://github.com/christian-deleon/dotfiles --skill docker
装完之后,当你让 AI 写 Dockerfile、compose.yaml、或者问”怎么用 BuildKit 多平台构建”,它会自动加载这个 Skill,给出 2026 年的 modern 答案。
谁适合用
如果你经常需要:
- 写生产级 Dockerfile(多阶段构建、安全加固、正确缓存)
- 维护
compose.yaml(Compose v2 新语法、watch 模式) - 做镜像供应链安全(签名、SBOM、扫描)
这个 Skill 值得装一个。它把 Docker 相关的”正确答案”固化下来,比每次对话重新摸索高效得多。
GitHub 仓库:https://github.com/christian-deleon/dotfiles
评论区
登录后可评论。