Analyze Docker image layers and suggest optimizations for size reduction, build speed, and caching efficiency.
Analyzes Docker images and Dockerfiles to suggest size, speed, and caching optimizations.
npx claudepluginhub jugrajsingh/skillgardenThis skill is limited to using the following tools:
Analyze Docker image layers and apply optimizations for size and build performance.
docker images {image_name} --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}"
docker history {image_name}:{tag} --no-trunc --format "table {{.Size}}\t{{.CreatedBy}}"
Glob: Dockerfile, Dockerfile.*
Read and analyze the current Dockerfile structure.
| Check | Optimization |
|---|---|
| Base image | Switch to alpine/slim/distroless |
| Multi-stage | Convert single-stage to multi-stage |
| Dev deps in runtime | Remove build tools from final stage |
| Package cache | Clean apt/apk cache in same RUN layer |
| Unnecessary files | Add to .dockerignore |
| Layer count | Combine related RUN commands |
| Check | Optimization |
|---|---|
| Layer ordering | Move frequently changing layers last |
| Cache mounts | Add --mount=type=cache for package managers |
| Dependency caching | Copy lock files before source code |
| BuildKit features | Enable DOCKER_BUILDKIT=1 |
| Check | Optimization |
|---|---|
| Lock file first | COPY package.json before COPY . |
| Source last | Application code copied last |
| Build cache | Use --mount=type=cache |
Gather image size, layer count, and Dockerfile content.
Compare against checklist and identify applicable improvements.
Show before/after comparison for each optimization with estimated impact.
Via AskUserQuestion:
If requested, rewrite Dockerfile with optimizations applied.
Use optimization-report.md template.
Before:
FROM python:3.12
COPY . .
RUN pip install -r requirements.txt
CMD ["python", "main.py"]
After:
FROM python:3.12-slim AS builder
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
FROM python:3.12-slim
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY . .
CMD ["python", "main.py"]
Before:
RUN pip install -r requirements.txt
After:
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -r requirements.txt
| From | To | Savings |
|---|---|---|
| python:3.12 | python:3.12-slim | ~700MB |
| node:20 | node:20-slim | ~600MB |
| ubuntu:22.04 | debian:bookworm-slim | ~50MB |