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.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Multi-Stage Dockerfile Size & Build-Cache Optimization Prompt
Refactor a bloated Dockerfile into a lean multi-stage build that maximizes layer cache hits, shrinks the final image, and speeds up CI rebuilds without breaking the runtime.
-
Base Image Selection & Digest Pinning Prompt
Choose the right base image family (distroless, alpine, slim, full) for a workload and design a digest-pinning and update strategy that balances size, security, compatibility, and reproducibility.
-
Docker Build Context Reduction & .dockerignore Audit Prompt
Audit a bloated Docker build context, identify what is being uploaded to the daemon unnecessarily, and produce a tuned .dockerignore plus COPY strategy that shrinks context and speeds builds.
-
BuildKit Cache Mount Strategy Design Prompt
Design a BuildKit cache-mount and cache-export strategy that speeds up dependency installs and compilation across local and CI builds without shipping cache into the final image.
More Docker with AI prompts & error guides
Browse every Docker with AI prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.