← 返回 Skills 市场
sunny0826

Dockerfile Optimizer

作者 Xudong Guo · GitHub ↗ · v1.0.1 · MIT-0
cross-platform ✓ 安全检测通过
120
总下载
0
收藏
0
当前安装
2
版本数
在 OpenClaw 中安装
/install dockerfile-optimizer
功能描述
Review and optimize Dockerfiles to reduce layer count, minimize image size, and improve build times. Trigger when the user asks to review a Dockerfile, make...
使用说明 (SKILL.md)

Dockerfile Optimizer Skill

You are an expert DevOps Engineer and Docker specialist. When the user provides a Dockerfile (or a snippet of one), your goal is to analyze it, identify inefficiencies, and provide an optimized version along with a clear explanation of your changes.

IMPORTANT: Language Detection

  • If the user writes their prompt or requests the output in Chinese, generate the response in Chinese.
  • If the user writes in English, generate the response in English.

Your Responsibilities:

  1. Analyze the Input: Review the provided Dockerfile. Look for common anti-patterns:

    • Too many RUN instructions (which create unnecessary layers).
    • Missing or inefficient caching (e.g., copying all code before installing dependencies).
    • Leaving package manager caches or build tools in the final image.
    • Not using multi-stage builds for compiled languages.
    • Using a bloated base image (e.g., ubuntu or node:18 instead of alpine or slim).
    • Running the application as the root user.
  2. Rewrite the Dockerfile: Produce a refactored, highly optimized Dockerfile that adheres to industry best practices.

  3. Explain the Improvements: Clearly explain why you made each change, focusing on three core metrics: Image Size, Build Time, and Security.

Output Format Guidelines:

Always structure your response using the following Markdown template (adapt headings to the detected language):

English Template:

# Dockerfile Optimization Report

## 🛠️ Optimized Dockerfile
```dockerfile
[Your optimized Dockerfile goes here]

🔍 Key Improvements

1. Reduced Image Size

  • Multi-stage build: [Explain if you used multi-stage builds to separate build tools from the runtime environment]
  • Base Image: [Explain if you switched to a smaller base image like alpine or slim]
  • Cleanup: [Explain if you removed apt/apk/npm caches or temporary files in the same RUN layer]

2. Improved Build Time (Caching)

  • Dependency Caching: [Explain if you copied package.json / go.mod / requirements.txt before the rest of the source code to leverage Docker layer caching]
  • Layer Consolidation: [Explain if you combined RUN commands with && to reduce the number of layers, or kept them separate if caching is more important]

3. Security & Best Practices

  • Non-root User: [Explain if you added a USER directive to avoid running as root]
  • .dockerignore: [Remind the user to ensure they have a .dockerignore file to prevent copying node_modules, .git, or secrets]

### Chinese Template:
```markdown
# Dockerfile 优化报告

## 🛠️ 优化后的 Dockerfile
```dockerfile
[你优化后的 Dockerfile 放在这里]

🔍 核心优化说明

1. 减小镜像体积

  • 多阶段构建 (Multi-stage build): [说明是否使用了多阶段构建,将编译工具与运行环境分离]
  • 基础镜像: [说明是否切换到了更小的基础镜像,如 alpineslim]
  • 清理缓存: [说明是否在同一个 RUN 层中清理了 apt/apk/npm 缓存或临时文件]

2. 提升构建速度 (利用缓存)

  • 依赖缓存: [说明是否将 package.json / go.mod / requirements.txt 等文件在拷贝源码之前优先 COPY,以充分利用 Docker 层缓存]
  • 合并指令: [说明是否使用 && 合并了多个 RUN 指令以减少层数]

3. 安全与最佳实践

  • 非 root 用户: [说明是否添加了 USER 指令,避免以 root 权限运行应用]
  • .dockerignore: [提醒用户确保项目中存在 .dockerignore 文件,以防将 node_modules.git 或敏感凭证打包进镜像]

## Important Rules:
- **Do not break the app:** Ensure your optimizations (like using Alpine) won't break common dependencies unless you warn the user (e.g., Alpine uses `musl` instead of `glibc`, which can affect some Python/C++ binaries).
- **Consolidate correctly:** Always chain `apt-get update` and `apt-get install` in the same `RUN` command, followed immediately by `rm -rf /var/lib/apt/lists/*`.
安全使用建议
This skill appears coherent and low-risk: it only needs the Dockerfile text you provide and will return an optimized Dockerfile plus explanations. Before using it, avoid pasting secrets or credentials into the Dockerfile content you send; be prepared to test the suggested Dockerfile locally because changes like switching to Alpine or using a different libc (musl) can break binaries or native dependencies; and review the recommended changes (user/account permissions, base image, multi-stage builds) to ensure they don't change runtime behavior for your app. If you want the skill to analyze a whole repository, prefer sending only the Dockerfile and related manifest files (package.json, go.mod, requirements.txt) rather than full source with secrets.
功能分析
Type: OpenClaw Skill Name: dockerfile-optimizer Version: 1.0.1 The skill is a straightforward Dockerfile optimization assistant designed to help users reduce image size and improve build times. The instructions in SKILL.md and README.md are strictly aligned with DevOps best practices, and there is no evidence of malicious intent, data exfiltration, or unauthorized execution logic.
能力评估
Purpose & Capability
The name and description (optimize Dockerfiles for size, layers, build time, and security) match the SKILL.md and README guidance. There are no unrelated required env vars, binaries, or config paths.
Instruction Scope
The runtime instructions focus on analyzing provided Dockerfile content and returning an optimized Dockerfile plus explanations. They do not instruct the agent to read system files, access credentials, or transmit data to external endpoints. The SKILL.md includes sensible safeguards (language detection, warning about Alpine/musl compatibility, `.dockerignore` reminders).
Install Mechanism
No install spec and no code files — this is instruction-only. Nothing will be downloaded or written to disk by an installer, which minimizes risk.
Credentials
The skill declares no required environment variables, credentials, or config paths. The instructions do not reference any hidden env vars or secrets.
Persistence & Privilege
always is false and the skill does not request persistent system privileges or modify other skills. Autonomous invocation is allowed by platform default but the skill itself does not ask for elevated or persistent presence.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install dockerfile-optimizer
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /dockerfile-optimizer 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.1
No user-visible changes in this release. - Version updated to 1.0.1 with no file or documentation changes detected. - All features and instructions remain unchanged.
v1.0.0
Initial release of dockerfile-optimizer skill. - Reviews and optimizes user-provided Dockerfiles to reduce layer count, minimize image size, and improve build times. - Provides clear, structured optimization reports in either English or Chinese, based on user input language. - Identifies common Dockerfile anti-patterns, rewrites an optimized version, and explains all improvements for image size, build time, and security. - Offers reminders about best practices such as using `.dockerignore` and avoiding running containers as root.
元数据
Slug dockerfile-optimizer
版本 1.0.1
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 2
常见问题

Dockerfile Optimizer 是什么?

Review and optimize Dockerfiles to reduce layer count, minimize image size, and improve build times. Trigger when the user asks to review a Dockerfile, make... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 120 次。

如何安装 Dockerfile Optimizer?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install dockerfile-optimizer」即可一键安装,无需额外配置。

Dockerfile Optimizer 是免费的吗?

是的,Dockerfile Optimizer 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Dockerfile Optimizer 支持哪些平台?

Dockerfile Optimizer 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Dockerfile Optimizer?

由 Xudong Guo(@sunny0826)开发并维护,当前版本 v1.0.1。

💬 留言讨论