跳到正文
Skillpedia
部署与云(DevOps)18k · #10674

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/docker/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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 of latest for reproducibility.
  • Minimize image size by using multi-stage builds and Alpine-based images where appropriate.
  • Never run containers as root in production. Use USER directives in Dockerfiles.
  • Keep layers minimal — combine related RUN commands 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 .dockerignore to exclude node_modules, .git, build artifacts, and secrets.
  • Use COPY --from=builder in multi-stage builds to keep final images lean.
  • Set HEALTHCHECK instructions for production containers.
  • Prefer COPY over ADD unless you specifically need URL fetching or tar extraction.

Debugging Techniques

  • Use docker logs <container> and docker logs --follow for real-time output.
  • Use docker exec -it <container> sh to inspect a running container.
  • Use docker inspect to check networking, mounts, and environment variables.
  • For build failures, use docker build --no-cache to rule out stale layers.
  • Use docker stats and docker top for resource monitoring.

Compose Patterns

  • Use named volumes for persistent data. Never bind-mount production databases.
  • Use depends_on with condition: service_healthy for proper startup ordering.
  • Use environment variable files (.env) for configuration, but never commit secrets to version control.
  • Use docker compose up --build --force-recreate when 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 commit for production images — always use Dockerfiles for reproducibility.
常见问题

为什么要避免 latest 标签?

像 node:20-alpine 这样的具体标签能让构建可重现,而 latest 可能在没有警告的情况下改变。

如何查看容器失败的原因?

用 docker logs 查看输出,用 docker exec 进入容器内部,用 docker inspect 查看网络和挂载。

什么是多阶段构建?

它在一个阶段中构建应用,只把需要的文件复制到精简的最终镜像中。

详情

作者的原始描述

Docker expert for containers, Compose, Dockerfiles, and debugging

repo: RightNow-AI/openfang

热度

GitHub 星标
18k
排名
#10674
许可证
Apache-2.0
更新时间
2026/7/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能