Before / After
Before: you ask AI to “fix my Docker build” and get guesses back.
After: you give the failing layer, exact command, changed files, and environment context, so AI can separate a broken Dockerfile from a missing dependency, a cache issue, or a platform mismatch.
Why this matters
Docker build failures often look like they happen in one place while the real cause sits somewhere else. The log may point at npm install, apt-get, COPY, pip install, or another step, but the actual issue can be the base image, lockfile, network, cache, or the difference between a local machine and CI.
For a beginner, the goal is not to guess the first fix. It is to shrink the problem to one layer quickly.
What context to include
To keep AI from guessing, provide:
- the exact project and what it builds;
- the Dockerfile path;
- the base image and tag;
- the full build command;
- the environment: local, GitHub Actions, GitLab CI, other;
- what changed before the break;
- the exact error from the failing layer;
- what works and what does not.
If the build passes on one machine but fails in CI, that is already a strong clue. The difference often lives in platform, package manager version, network access, or cache behavior.
Common failure classes
Not every failure means “rewrite the Dockerfile.” The usual groups are:
- dependencies do not install because of the lockfile or registry;
- the base image changed and brought a different runtime or package manager;
COPYcannot find files because of.dockerignoreor the build context;- cache hides the problem locally, but CI rebuilds from scratch;
- a platform or OS difference changes behavior;
- the build fails in tests or artifact creation rather than in Docker itself.
In short
Docker build rarely breaks “just because.” If you give AI the failing layer, dependency changes, and the gap between local and CI, it can usually find the real cause faster than a generic “fix my build” request.
Quick checklist
- I included the exact build command and Dockerfile path.
- I pasted the failing layer, not just the last line.
- I said whether this happens locally, in CI, or both.
- I named recent changes to dependencies, base image, or lockfile.
- I called out any platform or environment differences.
- I know the smallest safe probe to run next.
Find the cause of a Docker build failure
Help me diagnose why this Docker build fails. Context: - Project: [name and what it builds] - Dockerfile path: [path] - Base image: [image and tag] - Build command: [exact command] - Where it fails: [local, GitHub Actions, GitLab CI, other] - What changed recently: [Dockerfile, lockfile, dependency, base image, platform, CI image] - Exact error: [paste the failing layer and last 20-40 lines] - What already works: [local run, unit tests, previous image, other machine] - What already failed: [steps you already tried] Please: 1. Identify the most likely failing layer. 2. Separate Dockerfile problems from dependency, lockfile, network, cache, or platform issues. 3. Tell me what evidence to check next. 4. Suggest the smallest safe probe to confirm the root cause. 5. If useful, show how to rewrite this request for another AI or teammate so they get the right context. Output format: - Likely root cause: - Why it fits: - What to check next: - Smallest probe: - If the build is flaky: - If it only fails in CI: