Your Image Is 2 GB and Nobody Knows Why: LLM Prompts That Read the Dockerfile, the Layers, and the Failed Deploy Step

A 2 GB image, a 15-minute CI run, and a deploy that died on a step that worked fine on your laptop. Three symptoms, one root cause nobody has time to dig out by hand — and the one tool that actually reads the evidence is the LLM you already have open in another tab. The trick is asking it the right question: not "make my Dockerfile smaller" (you'll get "use alpine" and a shrug), but "here are my layers, here is my Dockerfile, here is the failing log — name the step where the bytes come from."

Below are prompts that do exactly that. Each one is built around a real artefact you can paste: layer history, build log, pipeline YAML, the failed job output. Each one produces a diagnosis you can act on today.

Before any prompt, get the evidence. Without this output, the model is guessing from vibes:

docker history --no-trunc --format "table {{.ID}}\t{{.CreatedBy}}\t{{.Size}}" my-image:latest
docker image inspect my-image:latest --format '{{.Size}}'

The first column of docker history that matters is Size — the layer that says 1.4 GB next to an innocuous RUN apt-get install is your culprit. The second is CreatedBy — that's the actual shell command. Everything below assumes you paste both.

Myth: "The image is big because the base is big"

Usually false. python:3.11-slim is around 120 MB compressed. If your image is 2 GB, roughly 1.8 GB came from your own RUN and COPY steps — pip cache, build toolchains, node_modules, a forgotten --no-cache.

Prompt: Name the layer where the bytes come from

Prompt:

You are a Docker build auditor. Below is `docker history --no-trunc` output for one image and the Dockerfile that produced it.

Task:

1. Rank the top 5 layers by Size, descending. For each, quote the exact CreatedBy command.
2. For each, state in one sentence WHAT is inside that layer and WHY it is that big.
3. For each, say whether it is needed at runtime (yes/no) and what it would cost to remove or move it.
4. Do not recommend "use alpine" or "use slim" unless the base itself is in the top 3. If the base is not in the top 3, say so explicitly.

Output: a table with columns Layer

| Size | Command | What's inside | Runtime? | Fix.

<docker history output>
...

</docker history output>

<Dockerfile>
...

</Dockerfile>

Usage example: a Python service whose image ballooned from 400 MB to 2.1 GB after someone added RUN pip install -r requirements-dev.txt at the top of the Dockerfile. The model returned: layer 3, 1.1 GB, pip install -r requirements-dev.txt, contains pytest, mypy, black, and their transitive deps — none used at runtime. Layer 5, 600 MB, COPY.. including a local .venv/ and data/ directory the dev had forgotten to .dockerignore. Base was 130 MB and ranked 7th. That's the whole diagnosis — no alpine involved.

The.dockerignore is the cheapest fix you will ever make Before touching the Dockerfile, check whether a `.dockerignore` exists. Half the "mystery gigabytes" in a `COPY..` layer are local virtualenvs, node_modules, `.git`, and test fixtures that never needed to be in the build context.

Myth: "Multi-stage builds are always the answer"

Multi-stage is the right answer when the build toolchain is large and the runtime artefact is small — a Go binary, a compiled frontend, a Rust release. It is the wrong answer when the runtime genuinely needs the toolchain (a dev container, an ML image with CUDA and PyTorch, a build image itself).

Prompt: Decide whether multi-stage actually helps — with numbers

Prompt:

I want to know whether converting this Dockerfile to multi-stage will actually reduce the final image, and by how much. Do the arithmetic, not the sermon.

Inputs:

- Dockerfile: <paste>
- docker history with sizes: <paste>

Output:

1. Estimate the final image size under three strategies:
   (a) current single-stage, unchanged;

   (b) single-stage with .dockerignore and cache cleaning (`--no-cache-dir`, `rm -rf /var/lib/apt/lists/*`, etc.);

   (c) multi-stage with a builder and a runtime stage.

2. For each, list the exact layers you would expect and their approximate sizes.
3. Say which strategy wins and by how many megabytes. If (b) beats (c), say so — do not push multi-stage for its own sake.
4. Flag any layer that cannot be removed without breaking the runtime (shared libs, CUDA, language runtimes).

Usage example: a Go microservice. Single-stage: 890 MB. With .dockerignore and apt-get clean: 720 MB. Multi-stage with golang:1.22 builder and gcr.io/distroless/static-debian12: 18 MB. The model showed all three side by side and noted that the Go binary itself is 16 MB — the rest was the toolchain. That's the moment multi-stage earns its keep. A Node image with a native build step and a runtime that needs node_modules in place: the same prompt returned "multi-stage saves 40 MB, not worth the YAML complexity" — and that is the honest answer.

Myth: "If it builds locally, the deploy step is a CI problem"

If it builds on your laptop and fails in CI, the difference is almost never the pipeline YAML. It is one of: a missing secret, a different base image tag, a different architecture, a cache that masks the missing dependency, or a step that runs with a user that does not exist in the image.

Prompt: Diff the local build against the CI build

Prompt:

A build succeeds on my laptop (`docker build .`) and fails in GitHub Actions at step `<step name>`. I need a differential diagnosis, not a checklist.

Inputs:

- Dockerfile: <paste>
- The exact failing step from the CI log: <paste, including exit code>
- The CI pipeline YAML: <paste the build job>
- The base image tag used locally and in CI: <list both>

Task:

1. List the differences between the local and CI environments that could cause this exact failure. Rank by likelihood, given the log.
2. For each, the exact line in the log that supports or contradicts the hypothesis.
3. The minimum reproduction command I can run locally to trigger the same failure.
4. The fix — as a diff to the Dockerfile or the YAML, not as advice.

Usage example: a Node app that built fine locally and failed in CI with EACCES: permission denied, mkdir '/app/node_modules'. The model spotted that the CI job ran as USER node (set in the Dockerfile) but the COPY --chown=node:node was missing for package.json — locally, the developer ran as root, so the permission issue never surfaced. One-line fix: COPY --chown=node:node package*.json./. The prompt found it because it was told to look at the user, not because it was told to look at permissions.

Myth: "Caching is a YAML setting — turn it on and forget it"

Cache is a setting. Whether the cache actually hits is a Dockerfile layout question. If your COPY.. sits above the RUN pip install, every source change invalidates the dependency layer and you reinstall the world on every commit.

Prompt: Reorder the Dockerfile so the cache hits

Prompt:

Here is my Dockerfile. I want every layer that changes frequently to sit BELOW every layer that changes rarely, so the cache survives a source-code change.

Task:

1. For each instruction, classify as "changes rarely" (base image, system packages, dependency manifests) or "changes often" (source code, config, tests).
2. Propose a reordered Dockerfile with a one-line comment above each moved block explaining why it moved.
3. Estimate: on a typical commit that changes one source file, which layers will be cache hits and which will rebuild?
4. Flag any instruction whose position cannot be moved without breaking the build (e.g. a RUN that needs the source present).

<Dockerfile>
...

</Dockerfile>

Usage example: a Python service with COPY.. before RUN pip install -r requirements.txt. Reorder to COPY requirements.txt. → RUN pip install --no-cache-dir -r requirements.txt → COPY... Result on a one-file change: pip layer hits, source layer rebuilds. On a 2-minute pip install with 60 commits a day, that's roughly 2 hours of build time removed per day across the team — assuming the cache is wired up in CI, which the next prompt checks.

Cache invalidation on the base image A layer is only a cache hit if every layer above it is also a hit. If your base image tag is `python:3.11` (no digest), a base image push upstream silently invalidates everything below it. Pin to a digest when reproducibility matters more than getting security patches automatically.

Myth: "The pipeline is slow because the tests are slow"

Often it's not the tests. It's a step that rebuilds the image twice, a step with no cache mount, or a step that downloads the same thing the previous step already downloaded.

Prompt: Find where the 15 minutes actually go

Prompt:

Below is a GitHub Actions run with per-step timing. The whole job takes ~15 minutes. I need to know where the time actually goes, not where I think it goes.

Inputs:

- Job log with step names and durations: <paste>
- The build job YAML: <paste>

Task:

1. Sort steps by duration, descending. Give each step's share of total time as a percentage.
2. For each of the top 3, one sentence on what it is doing and one sentence on what could make it faster (cache, parallelism, skipping, splitting).
3. Flag any step that could be skipped entirely for this commit (e.g. docs-only change) and the exact `if:` condition to add.
4. State which single change would save the most wall-clock time.

Usage example: a job where the 15 minutes broke down as: docker build 6m, docker push 3m, tests 4m, checkout 30s, everything else under 1m. The model flagged that docker build ran twice — once in the test job and once in the deploy job, with no registry between them. Fix: build once, push with a tag, and pull in the deploy job. Saved roughly 6 minutes per run without touching the tests. More on the topic: “Docker, Kubernetes, and the LLM That Asks "Why?": Prompts That Diagnose a Pod Instead of Blindly Restarting It”.

Myth: "Prompting an LLM about Docker just gives you generic advice"

It does — if you ask a generic question. "How do I shrink my Docker image" earns you a Medium article. "Here are my 12 layers and their sizes, here is my Dockerfile, here is the failing log — where do the bytes come from" earns you a diagnosis. The difference is the evidence you paste. More on the topic: “Docker and Kubernetes: What Really Breaks in Production and How to Go from docker run to a Managed Cluster”.

If you want the same approach applied to the next layer up — pods, manifests, CrashLoopBackOff — the same evidence-first logic applies to Kubernetes. More on the topic: “From Dockerfile to Debugging Pods: 12 Prompts That Turn an LLM Into Your DevOps Partner”.

And when the failure is not in the image but in the pipeline itself — secrets, cache keys, matrix builds — there is a narrower kit for that. More on the topic: “CI/CD Without Surprises: 12 Prompts That Make the LLM Write Pipelines, Fix Broken Builds and Explain Terraform Plans in Plain English”.

What to actually do on Monday

Three things, in this order, and they cost you an hour:

  1. Run docker history --no-trunc on your largest image and paste it into the first prompt. You will almost certainly find one layer that is 60–90% of the size, and it will not be the base.
  2. Check whether .dockerignore exists and whether COPY.. is above your dependency install. Both are one-line fixes with disproportionate payoff.
  3. Paste the failing CI step and the local build command into the third prompt. The model needs the diff, not the error message — the error is the symptom, the diff is the cause.

Where the bytes usually hide, and what each prompt does about it

SymptomLikely sourcePrompt that diagnoses it
Image 2 GB, base is 130 MBpip/npm cache, dev deps, unignored local filesName the layer where the bytes come from
Multi-stage debated, no numbersToolchain size vs runtime size unclearDecide whether multi-stage actually helps
Builds locally, fails in CIUser, base tag, arch, missing secretDiff the local build against the CI build
Every commit reinstalls depsCOPY.. above the install stepReorder the Dockerfile so the cache hits
15-minute job, unknown causeImage built twice, no cache mountFind where the 15 minutes actually go

The pattern across all five prompts is the same: paste the artefact, ask for the mechanism, demand a diff instead of advice. That is the whole skill. The LLM is not going to know your image better than docker history does — but it will read docker history faster than you will, and it will not get bored at layer eleven. More on the topic: “Cybersecurity Course: What to Know Before You Start — Requirements, Pitfalls, and the Ethical Line Nobody Explains”.

← All posts

Ask AI about this article

Ask a question about this article — ASI Biont will answer based on its text.