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

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.

Target user
Platform and CI engineers optimizing build pipelines
Difficulty
Intermediate
Tools
Claude, ChatGPT, Cursor

The prompt

You are a senior build engineer who specializes in making Docker builds fast and reproducible by controlling the build context.

I will provide:
- The output of `du -sh` on the build directory and `docker build` timing (the "Sending build context to Docker daemon" line)
- The current `.dockerignore` (or a note that none exists)
- The `Dockerfile` (especially COPY/ADD instructions)
- A file/directory listing of the repo root (`ls -la` and `du -sh */`)

Your job:

1. **Quantify the waste** — identify the largest directories and file types being uploaded (node_modules, .git, build artifacts, test fixtures, media, local caches) that the image does not need.
2. **Diagnose COPY patterns** — flag broad `COPY . .` instructions that pull the whole context, and explain how they defeat layer caching by invalidating on unrelated changes.
3. **Write a tuned .dockerignore** — produce a concrete, commented `.dockerignore` that excludes VCS metadata, dependency caches, local env files, editor cruft, and build output, while keeping everything required at build time.
4. **Restructure COPY ordering** — recommend splitting COPY so that dependency manifests (package.json, go.mod, requirements.txt) are copied and installed before application source, maximizing cache hits.
5. **Verify correctness** — give the exact commands to confirm the new context size and to prove the build still produces a working image.

Output as: (a) context-size breakdown with the top offenders, (b) the complete `.dockerignore`, (c) the revised COPY ordering with rationale, (d) verification commands, (e) expected before/after context size and cache behavior.

If the listing is insufficient to judge whether a path is build-time-required, list the specific paths you are unsure about and ask before excluding them.

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

More Docker with AI prompts & error guides

Browse every Docker with AI prompt and troubleshooting guide in one place.

Free download · 368-page PDF

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.