AgentSkillsCN

docker-optimization

优化Docker与Compose资产,实现快速、安全且可复现的构建流程。在Dockerfile或Compose文件发生变更时,或在提升镜像大小、启动可靠性与构建性能时使用。

SKILL.md
--- frontmatter
name: docker-optimization
description: Optimize Docker and Compose assets for fast, secure, and reproducible builds. Use when Dockerfile or compose changes are made, or when improving image size, startup reliability, and build performance.
license: MIT

Docker Optimization

When to Use This Skill

Use when changing Dockerfile/compose, or when improving image efficiency and reliability.

Optimization Workflow

  1. Keep multi-stage build boundaries clear (build/test vs runtime).
  2. Minimize runtime image contents and attack surface.
  3. Improve layer caching strategy (copy package manifests before sources where applicable).
  4. Validate healthcheck/startup behavior and exposed ports.
  5. Validate compose configuration and containerized test flows.
  6. Update root README.md if Docker workflows changed.

Optimization Rules

  • Prefer small trusted base images and regular rebuild cadence.
  • Keep .dockerignore tight to reduce context size.
  • Avoid unnecessary packages/tools in production image.
  • Run application as non-root where possible.

See docker optimization checklist.