Getting it into your agent
It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.
git clone --depth 1 https://github.com/Wade-DevCode/awesome-coding-skills-cnnpx agentmods add skills/wade-devcode/awesome-coding-skills-cn/docker-best-practicesWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/wade-devcode/awesome-coding-skills-cn/docker-best-practices)<a href="https://agentmods.dev/skills/wade-devcode/awesome-coding-skills-cn/docker-best-practices"><img src="https://agentmods.dev/badge/skills/wade-devcode/awesome-coding-skills-cn/docker-best-practices/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/skills/wade-devcode/awesome-coding-skills-cn/docker-best-practices"><img src="https://agentmods.dev/badge/skills/wade-devcode/awesome-coding-skills-cn/docker-best-practices.svg" alt="Reviewed on agentmods" width="80" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00029 | $0.02068 |
| Opus 5.5 | $0.00012 | $0.00827 |
| Sonnet 5.5 | $0.00006 | $0.00414 |
| Haiku 4.5 | $0.00003 | $0.00207 |
Grade A, and why
docker-best-practices scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Makes network callslowCapability
Not a fault in itself. Listed so you know the mod talks to something, and to what.
CMD wget -qO- http://localhost:8080/health || exit 1 How it starts
The opening of the file, as written. The whole thing — 170 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Docker 最佳实践
何时用
- 新写或修改任何 Dockerfile。
- 把现有应用容器化时做方案设计。
- 发现镜像体积异常大、构建反复拉依赖、容器以 root 身份运行时。
- 做镜像安全扫描前的自查。
核心规则
1. 多阶段构建 + 锁定基础镜像版本
规则: 用多阶段构建(multi-stage build)将编译工具与运行时分离;最终阶段只保留运行所需;基础镜像使用 slim 或 alpine 变体并固定具体版本标签,不用 latest。
为什么: AI 生成 Dockerfile 时惯用 FROM node:latest 并把构建工具一并打进最终镜像,导致:镜像体积从几十 MB 膨胀到数百 MB,latest 标签在不同时间拉取内容不同使构建不可重复,安全扫描面随之大幅增加。曾见过把 gcc、make、完整 Python 开发头文件留在生产镜像里的真实事故。
怎么做:
FROM node:20-alpine AS builder做编译,FROM node:20-alpine AS runtime只拷产物。- 用
COPY --from=builder /app/dist ./dist跨阶段拷贝,其余一概不带。 - 在 CI 中定期用
docker scout或trivy扫镜像,升版本时同步更新标签。
2. 善用层缓存:先装依赖再拷源码
规则: 把"依赖清单文件"(package.json、requirements.txt、go.mod 等)单独先 COPY 进去并执行安装,再 COPY 源码;源码修改不会使依赖层失效。
为什么: AI 最常见的写法是 COPY . . 然后 RUN npm install——每次改一行业务代码,整个依赖安装层失效,CI 上几分钟的 npm install 变成每次必跑。在依赖上百包的项目里这是显而易见的浪费,但 AI 很少主动意识到。
怎么做:
# 正确顺序:依赖清单 → 安装 → 源码
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
COPY src/ ./src/
- 每次只有
package.json变化才重新跑npm ci,改源码直接命中缓存。 - monorepo 场景先
COPY根package.json与各 workspace 的package.json,再统一安装。
3. 不以 root 运行;密钥不进镜像
规则: 用 USER 指令切换到无特权用户;通过 BuildKit secret 或运行时环境变量传入凭据,不用 ENV/ARG 把密钥固化进镜像层。
为什么: AI 生成的 Dockerfile 几乎从不加 USER 指令,容器进程默认以 root 运行,一旦容器被攻破即获宿主机高权限。同样,AI 会把 ARG NPM_TOKEN=xxx 写进 Dockerfile 并 RUN npm install,虽然 ARG 不出现在 docker inspect 环境变量里,但该层的文件系统快照仍可被 docker history 提取,密钥实质上已泄露。
怎么做:
# 创建专用用户
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser
# 用 BuildKit secret 挂载,不写进层
RUN --mount=type=secret,id=npm_token \
NPM_TOKEN=$(cat /run/secrets/npm_token) npm ci
- 运行时凭据通过
docker run --env-file或 Kubernetes Secret 注入,不烘进镜像。
4. 一容器一职责;用 .dockerignore 瘦身
规则: 单个容器只运行一个主进程(PID 1);项目根目录维护 .dockerignore,至少排除 .git、node_modules、测试目录、本地配置文件等。
为什么: AI 有时会在同一容器里启动 Nginx + App Server + Cron,把运维复杂度全转移到容器内,违背容器设计原则,日志、健康检查、横向扩展都难以独立处理。同样,AI 不会主动创建 .dockerignore,导致 COPY . . 把几百 MB 的 node_modules 或整个 .git 历史拷入构建上下文,build context 传输时间急剧增加。
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 1mo ago First seen · 170 lines · 29 tokens per session scan A 2c69b99a5f94
docker-best-practices is a skill published in the GitHub repository Wade-DevCode/awesome-coding-skills-cn (7 stars, last pushed 4mo ago), licensed MIT. It adds 29 tokens to every session and 2,068 once invoked, about $0.0001 per session on Opus 5.5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
Other skills, from other repositories
executing-plans
A procedure for carrying out a written software implementation plan in a separate session, including reviewing the plan, completing its tasks, and checking the results at defined review points.
chinese-git-workflow
A reference for configuring Git with Chinese code-hosting services such as Gitee, Coding.net, GitLab China, and CNB, including SSH, HTTPS, credentials, CI, and repository mirroring.
chinese-code-review
A Chinese-language code-review communication guide with templates and severity levels for review comments.
chinese-commit-conventions
A Chinese-language guide to Conventional Commits, a format for writing consistent Git commit messages, plus related changelog, commit-checking, and commit-helper configuration.
chinese-documentation
A Chinese technical-documentation style guide covering spacing, punctuation, numbers, terminology, and links when Chinese and English appear together.
systematic-debugging
A step-by-step method for finding the underlying cause of technical problems before changing code. It covers reading errors, reproducing failures, checking recent changes, and tracing data across system components.