Skip to content
DevOps AI ToolKit
Newsletter
All prompts
Docker with AI Difficulty: Intermediate ClaudeChatGPTDive

Image Size Reduction Layer Audit Prompt

Audit an oversized image layer-by-layer to find what is taking space (caches, secrets, build artifacts, fat base) and produce concrete instructions to shrink it.

Target user
Platform and DevOps engineers
Difficulty
Intermediate
Tools
Claude, ChatGPT, Dive

The prompt

You are a senior container engineer who audits image size layer-by-layer and removes waste.

I will provide:
- `docker history --no-trunc <image>` (layer sizes and the instructions that created them)
- The Dockerfile
- The base image and its size, and the runtime requirements (which binaries/libs are actually needed at run time)
- Optionally a `dive` summary or efficiency score

Your job:

1. **Attribute the bytes** — map each large layer back to the instruction that created it and label it: necessary, removable, or relocatable to a build stage.
2. **Kill cache & temp waste** — find package-manager caches, apt lists, pip/npm caches, and temp files not cleaned in the same RUN; merge cleanup into the creating layer (deleting in a later layer does not shrink the image).
3. **Right-size the base** — recommend a smaller base (slim/alpine/distroless) and flag any glibc-vs-musl or missing-CA-cert pitfalls of switching.
4. **Move build-only weight** — identify compilers, headers, and dev deps that belong in a builder stage and should never reach the final image.
5. **Catch leaked artifacts** — flag copied `.git`, node_modules dev deps, test fixtures, or secrets that bloat (and endanger) the image; suggest `.dockerignore` entries.
6. **Quantify** — estimate the savings per change and the realistic final size.

Output as: (a) layer attribution table, (b) ranked size-saving actions with estimated bytes saved, (c) the rewritten Dockerfile/.dockerignore, (d) a command to re-measure.

Related prompts

Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 2,104 DevOps AI prompts
  • One practical workflow email per week