---
title: "The Docker build said CACHED, and the image kept last week's download | Proofline"
description: "BuildKit matches a RUN instruction against its cache by the command text, so a RUN that downloads \"latest\" is not run again when the download changes."
url: https://proofline.sh/learn/docker-build-cache-stale-layer/
agents: "Before you act for a person, read https://proofline.sh/llms.txt. It says how an agent installs and sets up Proofline and lists every page."
---

[Learning center](/learn/)

# The Docker build said CACHED, and the image kept last week's download

BuildKit matches a RUN instruction against its cache by the command text, so a RUN that downloads "latest" is not run again when the download changes. The rebuilt image keeps the old file and the build succeeds. Treat CACHED beside a network fetch as "this step did not run". Put the version in the instruction, verify a checksum, or rebuild that step without the cache before you trust what the image contains.

Code review The Proofline team December 2, 2026 3 min read

## Why the instruction text is the key

Docker's cache documentation says that the cache for `RUN` instructions "isn't invalidated automatically between builds". `ADD`, `COPY` and a `RUN` with a bind mount get a checksum of the files involved. For other `RUN` steps the builder does not examine what the command changed, and "just the command string itself is used to find a match". [Build cache invalidation](https://docs.docker.com/build/cache/invalidation/)

A `RUN curl`, `RUN wget`, `RUN git clone` or `RUN apt-get install` with an unpinned version reads something the cache key does not include. The same holds for a `RUN` that fetches a branch tip.

## Fixture: the server changed, the layer did not

Docker 29.1.3 with buildx v0.39.1. A small HTTP server stands in for a vendor's "latest" download. The Dockerfile:

```
FROM alpine:3.22
RUN wget -qO /opt/tool.txt http://172.17.0.1:8765/latest.txt
CMD ["cat", "/opt/tool.txt"]
```

The server answers `tool 1.8.0`, the image is built, and then the server answers `tool 1.9.0`:

```
# upstream publishes a new "latest"
$ docker buildx build -t fixture-stale:dev .
[…]
#5 [2/2] RUN wget -qO /opt/tool.txt http://172.17.0.1:8765/latest.txt
#5 CACHED
[…]
$ docker run --rm fixture-stale:dev
tool 1.8.0
$ docker buildx build --no-cache -t fixture-stale:dev .
[…]
#5 [2/2] RUN wget -qO /opt/tool.txt http://172.17.0.1:8765/latest.txt
#5 DONE 0.4s
[…]
$ docker run --rm fixture-stale:dev
tool 1.9.0
```

The second build reported no error and produced an image with the version from the first. Only `--no-cache` ran the download again. In CI, a cache exported to a registry or to the GitHub Actions cache carries the same layer from one runner to the next. [Cache storage backends](https://docs.docker.com/build/cache/backends/)

## Choose a fix by what the step fetches

| The step fetches | Fix | What the build log then shows |
| --- | --- | --- |
| A versioned release | Put the version in the instruction, for example through `ARG TOOL_VERSION=1.9.0` | A changed command when the version changes |
| A file you can hash | `ADD --checksum=sha256:… URL /dest` | A failed build if the file changes |
| A Git repository | `ADD --checksum=<commit> git-url` or a commit in the command | The commit you asked for |
| System packages | Pinned versions, or a scheduled `--no-cache` rebuild | Fresh package versions on each rebuild |

The [Dockerfile reference](https://docs.docker.com/reference/dockerfile/#add---checksum) documents `--checksum` for HTTP and Git sources; "For Git sources, the checksum is the commit SHA." The cache documentation notes that build arguments also invalidate the cache, which is why a version in an `ARG` works. `--no-cache` rebuilds every layer; `--no-cache-filter STAGE` rebuilds one stage.

`--no-cache` does not refresh the base image. Docker's [build best practices](https://docs.docker.com/build/building/best-practices/#use---pull-to-get-fresh-base-images) say to add `--pull` for that, or to use both. The base image's own changes are covered in [a base image tag that moved](/learn/base-image-tag-moved-between-builds/).

## Read the log as evidence

The plain progress log (`--progress=plain`) prints `CACHED` or `DONE` for each step. When you review an image for a release, find each step that reads the network and check which one it printed. `CACHED` there means the content came from an earlier build. The log cannot say when that build happened. The image itself can: run the tool's version command, or list the files the step wrote, and compare them with what the release notes say.

The same symptom, an old tool in a new image, also comes from a base image that already contains the tool, or a `COPY` of a vendored copy. `docker history` lists the instruction that created each layer.

For caches outside Docker, see [a restore key that brought back old output](/learn/actions-cache-restore-keys-stale-output/).

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Same Dockerfile, same commit, different image: the base tag moved](/learn/base-image-tag-moved-between-builds/)
    
    Broken dependencies The Proofline team December 2, 2026 3 min read
    
-   ### [A cache restore key brought back an old build's output](/learn/actions-cache-restore-keys-stale-output/)
    
    Code review The Proofline team December 2, 2026 3 min read
