Docker 建置最佳化
Docker 建置最佳化
改善既有 Dockerfile 的快取、映像大小與建置秘密處理。
Docker · 官方來源 · DevOps 與基礎架構
來源狀態
可用來源
資源類型
Skill
與類似 Skill 有什麼不同?
- Docker 破壞性操作防護
Docker Build Strategies 改善映像建置與分層;Docker Destructive Guardrails 約束 prune、刪除 volume 等破壞性操作。
來源描述的能力
這些是來源描述的可能操作,不代表 2lus 已授予權限或已測試。
- 讀取檔案
- 寫入檔案
- Shell 指令
- Docker 操作
這個 Skill 是什麼?
從已存在的建置流程分析失效的 layer cache、重複下載及多階段產物邊界,提出可比較的改善方案。
可以做什麼?何時適合使用?
- Maven dependencies 每次重新下載。
- 最終映像包含 compiler 或開發依賴。
- CI cache 與本機結果不一致。
如何使用
- 提供 Dockerfile、去識別化 build log 與目前映像大小。
- 定位 COPY 順序、依賴解析與 runtime stage 的問題。
- 提出最小修改與冷/暖 cache 比較計畫;取得同意後才執行量測。
使用前你需要準備
- Dockerfile 或 workflow
- 服務依賴與部署限制
你可以替換:
[service]、[environment]
環境與相依需求
- Docker 23+ 建議使用 BuildKit;20.10–22 需明確啟用 BuildKit。
使用範例與 Prompt
以下是 2lus 撰寫的示範需求;請替換為你有權處理的檔案與專案,不代表已執行或保證結果。
入門
檢閱這份 Dockerfile,指出最終 image 中哪些 build tools 可以移至 builder stage;先不要修改。
實務
目前 Maven dependencies 每次都重新下載,請調整 Dockerfile 的 layer ordering 並解釋 cache 失效條件。
進階
替現有 CI build 設計 multi-stage、BuildKit cache 與 secret mount 改善,保留可重現的依賴版本,列出冷暖 cache 和 runtime 相容性驗收方式。
實用提醒
- 比較冷 cache 與暖 cache,避免只記錄單次最快數字。
限制與注意事項
- 縮小映像不保證相容;原生套件與 runtime 動態函式庫需另外驗證。
安全注意事項
- 秘密使用受支援的 secret mount,不放在 ARG、ENV 或 COPY 層。
使用與設定
來源 README 的互動式安裝方式;選擇需要的 Skill 與宿主。此處只能複製,不會執行。
npx skills add docker/skills官方文件 ↗
支援平台
Claude Code — 文件記載,未做實機相容性測試 官方文件 ↗
Codex — 文件記載,未做實機相容性測試 官方文件 ↗
Cursor — 文件記載,未做實機相容性測試 官方文件 ↗
GitHub Copilot — 文件記載,未做實機相容性測試 官方文件 ↗
來源與授權
來源查核日期(非安全認證): 2026-09-29
Apache-2.0
原始來源 ↗ 授權條款 ↗ 官方文件 ↗相關 Skills
使用第三方 Skill 前,請先檢查來源、權限與執行內容。安裝指令只供查看與複製,不會由 2lus 執行。
2lus AI Skills Library 提供 Skill 的整理與使用導覽。第三方 Skill 的內容、授權與可用性以原始來源為準。使用或安裝前,請自行確認其權限與執行內容。
Docker Build Strategies
Improve caching, image size and secret handling in an existing Docker build.
Docker · Official source · DevOps & Infrastructure
Source status
Active source
Resource type
Skill
How is this different from similar skills?
- Docker Destructive Guardrails
Docker Build Strategies improves image construction and layers; Docker Destructive Guardrails constrains pruning, volume deletion and other destructive actions.
Documented capabilities
These are operations described upstream, not permissions granted or tested by 2lus.
- Read files
- Write files
- Shell commands
- Docker operations
What is this skill?
Trace cache invalidation and unnecessary artifacts in an established Dockerfile, then propose measurable changes to stage boundaries.
Use cases and when to use it
- Maven downloads repeat on every build.
- Compiler tools remain in the runtime image.
- CI and local cache behavior diverge.
How to use it
- Provide the Dockerfile, sanitized build log and current image size.
- Locate COPY ordering, dependency resolution and runtime-stage issues.
- Propose a minimal patch and cold/warm comparison; obtain approval before measurement.
What you need
- Dockerfile or workflow
- Service dependencies and deployment constraints
You can replace:
[service], [environment]
Environment and dependencies
- Docker 23+ with BuildKit recommended; enable BuildKit explicitly on 20.10–22.
Usage and prompt examples
These example requests were written by 2lus. Substitute files and projects you may use; examples are not executed results or guarantees.
Beginner
Review this Dockerfile and identify build tools that can leave the final image. Do not edit yet.
Practical
Maven dependencies download every time. Improve layer ordering and explain which changes invalidate each cache.
Advanced
Design a minimal CI update using multiple stages, BuildKit caching and secret mounts. Preserve pinned dependencies and define cold/warm and runtime compatibility checks.
Tips
- Compare cold and warm caches instead of reporting only the fastest run.
Limitations
- A smaller image may omit native libraries needed at runtime.
Security notes
- Use supported secret mounts; never bake secrets into ARG, ENV or copied layers.
Usage and setup
Interactive installation documented in the README; select skills and host. This page only copies the command.
npx skills add docker/skillsDocumentation ↗
Supported agents
Claude Code — Documented; not runtime-tested Documentation ↗
Codex — Documented; not runtime-tested Documentation ↗
Cursor — Documented; not runtime-tested Documentation ↗
GitHub Copilot — Documented; not runtime-tested Documentation ↗
Sources and license
Source check date (not a safety certification): 2026-09-29
Apache-2.0
Original source ↗ License terms ↗ Documentation ↗Related skills
Before using a third-party skill, review its source, permissions and executable content. Commands are for viewing and copying only; 2lus does not execute them.
2lus AI Skills Library provides curated educational guides. Third-party content, licenses and availability are governed by their original sources. Review permissions and executable content before use or installation.