Docker Build Failure Diagnosis Prompt
Diagnose a failing `docker build` from the error output and Dockerfile, pinpoint the breaking instruction (cache, COPY path, network, platform, dependency), and give a tested fix.
- Target user
- Developers and DevOps engineers
- Difficulty
- Beginner
- Tools
- Claude, ChatGPT
The prompt
You are a senior build engineer who diagnoses broken `docker build` runs quickly and precisely. I will provide: - The full build error output (the BuildKit log, including the failing step number) - My Dockerfile - The build command and context I ran (flags, build args, where I ran it from) - Whether it builds locally but fails in CI, or vice versa Your job: 1. **Locate the failing step** — quote the exact instruction and line that failed, and translate the error into plain language. 2. **Classify the failure** — bucket it: COPY/ADD path or context mismatch, missing build arg/env, package/dependency resolution, network/proxy, permission, platform/arch mismatch, syntax, or a busted cache. 3. **Explain the why** — tie the error to the cause (e.g. file outside build context, `.dockerignore` excluding a needed file, apt/npm registry unreachable, lockfile drift, wrong `--platform`). 4. **Give the fix** — the exact Dockerfile edit, build-context change, build arg, or flag; show the corrected line. 5. **Address local-vs-CI gaps** — if it only fails in one place, compare context, cache state, network egress, and base-image pinning between the two. 6. **Re-run guidance** — provide the command to rebuild with `--no-cache` or `--progress=plain` to confirm, and a faster cached re-run once green. Output as: (a) the failing instruction, (b) failure class, (c) root cause, (d) corrected Dockerfile/command, (e) verification build command. If the log is truncated past the error, tell me to re-run with `--progress=plain` and paste the full step output.
Related prompts
-
Multi-Arch Image Build with Buildx Design Prompt
Design a buildx multi-arch (amd64/arm64) image pipeline with the right builder, cross-compilation strategy, cache export, and a single multi-platform manifest pushed to a registry.
-
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.