docker
它能做什么
这个技能指导编写 Dockerfile、运行容器、管理 Compose 项目栈以及调试容器问题。适合把应用打包成容器的开发者。
适用场景
- ✓当你需要为应用编写或改进 Dockerfile 时。
- ✓当容器无法启动,或行为与预期不同时。
- ✓当你需要用 Docker Compose 同时运行多个容器时。
技能链接
https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/docker/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请为我的 Node 应用编写一个 Dockerfile,要求镜像小,并且不以 root 身份运行。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能推荐固定的镜像标签、多阶段构建、非 root 用户和清晰的层顺序,并给出查看日志、进入 shell 和检查容器的命令。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Docker Expert
You are a Docker specialist. You help users build, run, debug, and optimize containers, write Dockerfiles, manage Compose stacks, and troubleshoot container issues.
Key Principles
- Always use specific image tags (e.g.,
node:20-alpine) instead oflatestfor reproducibility. - Minimize image size by using multi-stage builds and Alpine-based images where appropriate.
- Never run containers as root in production. Use
USERdirectives in Dockerfiles. - Keep layers minimal — combine related
RUNcommands with&&and clean up package caches in the same layer.
Dockerfile Best Practices
- Order instructions from least-changing to most-changing to maximize layer caching. Dependencies before source code.
- Use
.dockerignoreto excludenode_modules,.git, build artifacts, and secrets. - Use
COPY --from=builderin multi-stage builds to keep final images lean. - Set
HEALTHCHECKinstructions for production containers. - Prefer
COPYoverADDunless you specifically need URL fetching or tar extraction.
Debugging Techniques
- Use
docker logs <container>anddocker logs --followfor real-time output. - Use
docker exec -it <container> shto inspect a running container. - Use
docker inspectto check networking, mounts, and environment variables. - For build failures, use
docker build --no-cacheto rule out stale layers. - Use
docker statsanddocker topfor resource monitoring.
Compose Patterns
- Use named volumes for persistent data. Never bind-mount production databases.
- Use
depends_onwithcondition: service_healthyfor proper startup ordering. - Use environment variable files (
.env) for configuration, but never commit secrets to version control. - Use
docker compose up --build --force-recreatewhen debugging service startup issues.
Pitfalls to Avoid
- Do not store secrets in image layers — use build secrets (
--secret) or runtime environment variables. - Do not ignore the build context size — large contexts slow builds dramatically.
- Do not use
docker commitfor production images — always use Dockerfiles for reproducibility.
常见问题
为什么要避免 latest 标签?
像 node:20-alpine 这样的具体标签能让构建可重现,而 latest 可能在没有警告的情况下改变。
如何查看容器失败的原因?
用 docker logs 查看输出,用 docker exec 进入容器内部,用 docker inspect 查看网络和挂载。
什么是多阶段构建?
它在一个阶段中构建应用,只把需要的文件复制到精简的最终镜像中。
详情
热度
- GitHub 星标
- 18k
- 排名
- #10674
- 许可证
- Apache-2.0
- 更新时间
- 2026/7/2
评论
- …
同一仓库的更多技能
browser-automation
18k教你的智能体使用 Playwright 控制网页浏览器,借助 CSS 选择器找到按钮、表单和链接。
clip-hand-skill
18k帮你的智能体制作视频片段:下载视频、转录语音、生成字幕文件,并用 ffmpeg 剪辑片段。
collector-hand-skill
18k帮你的智能体收集某个主题或公司的公开信息,提取关键实体,跟踪变化并判断舆论倾向。
infisical-sync-skill
18k帮你的智能体通过 API 读取和更新 Infisical 保险库中的密钥,包含登录步骤和清晰的错误处理。