Back to Cookbook

Image Slimmer

Shrink your container image from 1.2 GB to 120 MB

Analyzes your Dockerfile for bloat, bad layer ordering, missing multi-stage builds, and security issues. Generates an optimized version that builds faster, runs smaller, and has fewer CVEs.

House RecipeWork1 min

INGREDIENTS

🐙GitHub

PROMPT

Create a skill called "Image Slimmer". When I provide a Dockerfile (pasted or as a file path), analyze it and produce an optimized version: 1. Check for multi-stage build opportunities (separate build and runtime stages) 2. Optimize layer ordering for cache efficiency (dependencies before source code) 3. Recommend a smaller base image (alpine, distroless, Chainguard) if applicable 4. Remove unnecessary packages, build tools, and caches from the final image 5. Add security best practices (non-root USER, HEALTHCHECK, no secrets in build args) 6. Generate a .dockerignore if one doesn't exist 7. Run hadolint if available for additional lint checks For each change, explain why it matters (size reduction, build speed, security). If Docker is available, build both versions and show the size comparison.

How It Works

Paste your Dockerfile and get back an optimized version with explanations

for every change. It catches the patterns that turn a 50 MB app into a

1 GB image.

What You Get

  • Optimized Dockerfile with multi-stage build if applicable
  • Layer ordering optimized for cache efficiency
  • Base image recommendations (alpine, distroless, Chainguard)
  • Security improvements (non-root user, minimal packages, no secrets in layers)
  • .dockerignore generation to speed up build context
  • Before/after size comparison (when Docker is available)

Setup Steps

  1. Paste your Dockerfile or point your Claw at the file path
  2. Review the optimized version and the explanation for each change
  3. Build and compare sizes
  4. Iterate if you need specific packages or build steps preserved

Tips

  • Multi-stage builds are the single biggest win for most Dockerfiles
  • Layer ordering matters: put things that change rarely (apt install) before things that change often (COPY . .)
  • `docker history` reveals which layers are contributing the most bloat
  • If Docker is available, ask your Claw to build both versions and compare
Tags:#docker#containers#optimization#devops