跳到主内容
智客 ZICQ

技能库 智客分类:运维与云 docker-optimization

Docker Optimization

优化 Docker 图像和容器的大小、 构建速度和运行时性能

72 安装量

官方网址:skills.sh

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

优化 Docker 图像和容器的大小、 构建速度和运行时性能

何时用

官方 description 未单独写出 Use when。按规范,代理会在用户任务与这段 description 的关键词匹配时激活本技能。

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:Docker Optimization Skill、Purpose、Parameters、Optimization Strategies、1. Image Size Reduction、Before: 1.2GB。

文件分析

文件分析:这是一份仅含 SKILL.md 的指令型技能,代理激活后整份正文进入上下文。

官方 description(原文)

Optimize Docker images and containers for size, build speed, and runtime performance

Docker Optimization SkillPurposeParametersOptimization Strategies1. Image Size ReductionBefore: 1.2GBAfter: 150MB (88% smaller)Bad: 3 layers, 150MBGood: 1 layer, 50MBClean package manager cacheUse .dockerignorenode_modules, .git, *.md, tests/, docs/

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
docker-optimization
description
Optimize Docker images and containers for size, build speed, and runtime performance
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「docker-optimization」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-d83eaa1c6f961696-%E5%B5%8C%E5%85%A5%E4%BC%98%E5%8C%96.html
请存为 .cursor/skills/docker-optimization/SKILL.md 或 .claude/skills/docker-optimization/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/pluginagentmarketplace/custom-plugin-docker' --list

npx skills add 'https://github.com/pluginagentmarketplace/custom-plugin-docker' --skill 'docker-optimization'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版
--- name: docker-optimization description: Optimize Docker images and containers for size, build speed, and runtime performance sasmp_version: "1.3.0" bonded_agent: 02-docker-images bond_type: PRIMARY_BOND --- # Docker Optimization Skill Comprehensive optimization techniques for Docker images and containers covering size reduction, build caching, and runtime performance. ## Purpose Reduce image size, improve build times, and optimize container performance using 2024-2025 industry best practices. ## Parameters | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | target | enum | No | all | size/build/runtime/all | | base_image | string | No | - | Current base image | | current_size | string | No | - | Current image size | ## Optimization Strategies ### 1. Image Size Reduction #### Base Image Selection | Base | Size | Use Case | |------|------|----------| | scratch | 0 | Static Go/Rust binaries | | distroless | 2-20MB | Production containers | | alpine | 5MB | General purpose | | slim | 80-150MB | When apt packages needed | | full | 500MB+ | Development only | ```dockerfile # Before: 1.2GB FROM node:20 # After: 150MB (88% smaller) FROM node:20-alpine ``` #### Layer Optimization ```dockerfile # Bad: 3 layers, 150MB RUN apt-get update RUN apt-get install -y curl RUN rm -rf /var/lib/apt/lists/* # Good: 1 layer, 50MB RUN apt-get update && \ apt-get install -y --no-install-recommends curl && \ rm -rf /var/lib/apt/lists/* ``` #### Remove Unnecessary Files ```dockerfile # Clean package manager cache RUN npm cache clean --force RUN pip cache purge RUN apt-get clean && rm -rf /var/lib/apt/lists/* # Use .dockerignore # node_modules, .git, *.md, tests/, docs/ ``` ### 2. Build Speed Optimization #### Layer Caching Strategy ```dockerfile # Dependencies first (rarely change) COPY package*.json ./ RUN npm ci # Source code last (frequently changes) COPY . . RUN npm run build ``` #### BuildKit Cache Mounts ```dockerfile # syntax=docker/dockerfile:1 FROM node:20-alpine # Cache npm packages RUN --mount=type=cache,target=/root/.npm \ npm ci # Cache pip packages RUN --mount=type=cache,target=/root/.cache/pip \ pip install -r requirements.txt ``` #### Parallel Multi-Stage ```dockerfile # Parallel stages (BuildKit) FROM node:20-alpine AS deps COPY package*.json ./ RUN npm ci FROM deps AS builder COPY . . RUN npm run build FROM deps AS linter COPY . . RUN npm run lint ``` ### 3. Runtime Performance #### Resource Limits ```yaml services: app: deploy: resources: limits: cpus: '1' memory: 512M reservations: cpus: '0.5' memory: 256M ``` #### Container Tuning ```bash # Set memory limits docker run --memory=512m --memory-swap=512m app # CPU limits docker run --cpus=1.5 app # I/O limits docker run --device-read-bps=/dev/sda:1mb app ``` ## Optimization Checklist ### Size Checklist - [ ] Using smallest viable base image? - [ ] Multi-stage build implemented? - [ ] Package manager cache cleaned? - [ ] Dev dependencies excluded? - [ ] .dockerignore configured? ### Build Speed Checklist - [ ] Dependencies copied before code? - [ ] BuildKit enabled? - [ ] Cache mounts used? - [ ] Parallel stages where possible? ### Runtime Checklist - [ ] Resource limits set? - [ ] Health checks configured? - [ ] Non-root user? - [ ] Read-only filesystem where possible? ## Analysis Tools ```bash # Image size analysis docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}" # Layer analysis docker history --format "{{.Size}}\t{{.CreatedBy}}" # Deep dive analysis dive # Build time analysis DOCKER_BUILDKIT=1 docker build --progress=plain . ``` ## Error Handling ### Common Issues | Issue | Cause | Solution | |-------|-------|----------| | Large image | No multi-stage | Implement multi-stage | | Slow builds | Poor layer order | Dependencies before code | | Cache not working | Context changes | Use .dockerignore | | OOM at runtime | No limits | Set memory limits | ## Troubleshooting ### Debug Checklist - [ ] BuildKit enabled? (`DOCKER_BUILDKIT=1`) - [ ] Cache being used? (Check build output) - [ ] .dockerignore working? (Check context size) - [ ] Layers optimized? (Run `dive`) ## Usage ``` Skill("docker-optimization") ``` ## Related Skills - docker-multi-stage - dockerfile-basics - docker-production

相关技能

运维与云

Docker Essentials

用于容器管理,图像操作,调试的基本道克命令和工作流程.

运维与云

Find Skills

从开放的代理技能生态系统中发现并安装技能. 使用时:(1)用户问"我如何做X",X可能拥有现有技能,(2)用户说"为X找到技能"或"是否为X有技能",(3)用户问"你能否做X",X是专门能力,(4)用户想扩展代理能力,(5)用户想搜索工具,模板,或工作流程,(6)用户提到他们希望…

运维与云

Microsoft Foundry

构建,部署,评价,优化,微调,管理微软创始代理,模型,资源最终结束. 用法:铸造、azd ai代理、azd 提供/部署、托管代理脚手架/开发/运行/部署/拖放、即时代理创建、创建代理、更新代理、添加代理工具、援引代理、代理.yaml、评估代理、批量活化、连续活化、持续监测、代理C…

运维与云

Azure Deploy

执行已有.azure/部署计划.md和基础设施文件的ALREADY-PREPARED应用程序的Azure部署。 当用户向 CREATE 请求新应用程序时, 请不要使用此技能 。 这种技能运行了 azd上行, azd 部署, trarraform 应用, 和 az 部署命令带有内置…