Skip to content

Home / Blog / Caching

Docker layer cache in GitHub Actions: gha, registry, inline and local, measured

Three Dockerfiles, seven cache set-ups and three cases on GitHub-hosted runners: seconds to rebuild, the size of each cache, and when a cache loses.

On GitHub-hosted runners the registry cache was the fastest backend for a one-line change in all three Dockerfiles we tried: 31 s for the Node image, 49 s for Go and 23 s for Python, medians of 6 runs. With nothing changed, every remote backend took 9 to 13 seconds. A cache is not always a win: for the Go image only 2 of the six cache set-ups had a lower median than building with no cache after a one-line change. Our Docker build cache guide has the full setup.

In short
  • Medians of 6 runs on GitHub-hosted runners: with nothing changed, every remote cache took 9 to 13 seconds, and the local cache 24 to 40.
  • After a one-line change the registry cache was fastest in all three images: 31 s for Node, 49 s for Go and 23 s for Python.
  • For the Go image, with no cache a build took 55 s, and only 2 of the six cache set-ups had a lower median than that after a one-line change.
  • gha with mode=max made the first build slowest: 156 s for the Node image, against 38 s with no cache.
  • After a one-line change mode=max was slower than mode=min, or level with it, on all three images.

We built three Dockerfiles with each of seven cache set-ups on GitHub-hosted runners, 6 times each, and give the median and the range in seconds. The Docker and GitHub facts were read from their own documentation on the date this post was last checked. The workflows, the three Dockerfiles and every timing are in a public repository, so you can run them yourself, and the action reference has the YAML for each backend.

Which Docker cache backend is fastest in GitHub Actions?

For the build after a one-line change, the one an ordinary push pays, the registry cache was fastest or level for fastest on all three images. Behind it, inline and gha with mode=min were level on Node and Python; on Go, inline was second and gha with mode=min was among the slowest. gha with mode=max was the slowest for Node and Go, and the local cache was the next slowest for Node. The ranges below overlap in places, so treat a gap smaller than the range as noise.

What the three columns are. Cold: this set-up’s own cache is empty, and the build also writes it. Nothing changed: the same source again, with the builder and everything it held removed first, so everything should come from the cache. One line changed: a build number in the main source file goes from 0 to 1. Each cell is the median of the runs, then the lowest and highest in brackets, in seconds. A time is the set-up of the builder, the cache restore and save where there is one, and the build with its push. The no-cache row pools all three cases, because with no cache they are the same build.

The Node image has three stages and 668 packages in its lockfile.

BackendColdNothing changedOne line changed
No cache38 (33 to 51)38 (33 to 51)38 (33 to 51)
gha, mode=min58 (47 to 66)10 (9 to 10)37 (33 to 40)
gha, mode=max156 (85 to 277)11 (8 to 15)54 (52 to 76)
registry, mode=min42 (39 to 52)12 (8 to 21)31 (24 to 39)
registry, mode=max69 (62 to 85)11 (8 to 12)33 (25 to 37)
inline49 (38 to 65)12 (10 to 17)37 (30 to 42)
local, with actions/cache85 (67 to 90)40 (34 to 52)43 (40 to 50)

The Go image has two stages and compiles a service that imports gin, grpc, pgx, Prometheus and zap.

BackendColdNothing changedOne line changed
No cache55 (44 to 64)55 (44 to 64)55 (44 to 64)
gha, mode=min62 (47 to 85)11 (7 to 12)65 (44 to 79)
gha, mode=max111 (78 to 147)10 (8 to 33)82 (71 to 94)
registry, mode=min56 (48 to 74)12 (8 to 14)49 (46 to 69)
registry, mode=max60 (56 to 65)11 (8 to 11)57 (51 to 58)
inline53 (48 to 65)10 (8 to 14)52 (45 to 61)
local, with actions/cache60 (56 to 73)29 (21 to 164)63 (55 to 82)

The Python image has one stage and installs numpy, pandas, scipy, scikit-learn, matplotlib and pyarrow.

BackendColdNothing changedOne line changed
No cache48 (42 to 62)48 (42 to 62)48 (42 to 62)
gha, mode=min67 (63 to 86)9 (8 to 10)25 (21 to 34)
gha, mode=max77 (67 to 77)11 (8 to 14)28 (20 to 35)
registry, mode=min54 (47 to 67)11 (8 to 17)23 (16 to 28)
registry, mode=max54 (49 to 63)11 (8 to 15)23 (16 to 26)
inline55 (49 to 64)13 (8 to 15)25 (16 to 29)
local, with actions/cache63 (53 to 80)24 (22 to 120)27 (26 to 34)
Bar chart. Seconds to build after a one-line change on GitHub-hosted runners, median of 6 runs, by image and cache backend. Node image: No cache 38 seconds, gha, mode=min 37 seconds, gha, mode=max 54 seconds, registry, mode=min 31 seconds, registry, mode=max 33 seconds, inline 37 seconds, local, with actions/cache 43 seconds. Go image: No cache 55 seconds, gha, mode=min 65 seconds, gha, mode=max 82 seconds, registry, mode=min 49 seconds, registry, mode=max 57 seconds, inline 52 seconds, local, with actions/cache 63 seconds. Python image: No cache 48 seconds, gha, mode=min 25 seconds, gha, mode=max 28 seconds, registry, mode=min 23 seconds, registry, mode=max 23 seconds, inline 25 seconds, local, with actions/cache 27 seconds.Node imageNo cache38gha, mode=min37gha, mode=max54registry, mode=min31registry, mode=max33inline37local, with actions/cache43Go imageNo cache55gha, mode=min65gha, mode=max82registry, mode=min49registry, mode=max57inline52local, with actions/cache63Python imageNo cache48gha, mode=min25gha, mode=max28registry, mode=min23registry, mode=max23inline25local, with actions/cache27
Seconds to build after a one-line change on GitHub-hosted runners, median of 6 runs, by image and cache backend. Data: studies/D2-docker-cache-backends, its workflows and every timing.

Is a Docker layer cache always faster than no cache?

No. When the step that changed is the slow one, a cache has little to give and still costs a read and a write. For the Go image the build that took 55 seconds with no cache took 49 with the registry cache and 82 with gha at mode=max after a one-line change. The registry result is within the range of the no-cache build, so the part that has to run again after a source change looks like where this build spends its time; we did not time the steps separately. For the Node image with no cache a build took 38 seconds and the best cached rebuild after a change took 31; gha at mode=max, at 54, and the local cache, at 43, were slower than building with no cache. The Python image is where a cache pays: building it took about 48 seconds uncached, and every backend rebuilt it in 23 to 28 seconds. So the question to ask of your own Dockerfile is how long the layers you would cache take to build, and how long the cache takes to read.

The first build of a new cache, the cold column, costs more than building with no cache for most of these: it has to export what it built. gha at mode=max was the extreme, at 156 seconds for Node (range 85 to 277) and 111 for Go, against 38 and 55 with no cache. That cost is paid again every time the cache is rebuilt, which is after it has been evicted or when its key changes.

Does mode=max make builds faster than mode=min?

Not in these three. Docker says mode=max is more likely to get cache hits because it also caches the layers of intermediate stages, and the Node and Go images have such stages: a build stage whose files are copied into the last one, not the stage itself. For the one-line change, registry at mode=max took 33, 57 and 23 seconds for Node, Go and Python against 31, 49 and 23 at mode=min, and gha at mode=max took 54, 82 and 28 against 37, 65 and 25. The Python image has one stage, so the two modes cache the same layers and the difference between them is variation. The cache sizes below show max doing what Docker describes on the other two, storing far more, and for these builds it did not pay back in time. A Dockerfile whose slow stage is rebuilt more often than ours would not have to agree.

How big is a Docker cache in GitHub Actions?

Bigger at mode=max, sometimes by a lot. The table gives the size of the cache each set-up stores after the first build, in megabytes as stored (compressed). The inline cache lives inside the image you push, so it is not listed.

ImageBackendMegabytes
Nodegha, mode=min175
Nodegha, mode=max633
Noderegistry, mode=min175
Noderegistry, mode=max633
Nodelocal633
Gogha, mode=min47
Gogha, mode=max504
Goregistry, mode=min47
Goregistry, mode=max504
Golocal504
Pythongha, mode=min241
Pythongha, mode=max241
Pythonregistry, mode=min241
Pythonregistry, mode=max241
Pythonlocal241

GitHub keeps 10 GB of Actions cache per repository by default, bills anything beyond that, and deletes the least recently used entries once a repository is over it, so the gha and local backends share that space with every other cache you keep, such as the dependency caches the limit post covers. Ten images the size of the Node image at mode=max would use about 6 GB of it, a figure that is arithmetic and not a measurement. The registry cache does not count against it: it lives in a registry and is subject to that registry’s own limits and charges. Our layer cache documentation and our page on a Docker layer cache for GitHub Actions say what a runners.io job keeps between runs without any of this.

How was this measured?

One job per image and backend ran three builds in a row, each on a new BuildKit builder after the previous builder and the Docker daemon’s images had been removed, so only the cache backend carried anything over. Every build pushed its image to GHCR with the repository’s own token. The runner image was ubuntu-24.04, on 17 November 2026 (two image versions, 20261111.127.1 and 20261111.370.1, were handed out across the jobs), using docker/setup-buildx-action v4.4.1 and docker/build-push-action v7.4.0. The whole set was run 6 times, one after another, never together, and the cache entries in GitHub’s cache were deleted between repetitions. The 21 jobs of one repetition did run at the same time, in one repository, and the gha cache stores layers by digest, so a layer the base images share with another job can already be there when a gha job starts. The gha and local sizes are single readings, one build per Dockerfile and mode in an otherwise quiet repository, not medians. The images are small next to a large monorepo’s, the registry was GHCR on GitHub’s own network, and runner and network speed vary from job to job, which is what the range shows. A registry elsewhere, or a bigger build, can rank the backends differently. The Dockerfiles, the workflow, the method and every row are in the measurements repository.

Sources

Frequently asked questions

Which Docker cache backend is fastest in GitHub Actions?

By median, the registry cache was fastest for a one-line change on all three Dockerfiles we tried, at 31, 49 and 23 seconds, though the ranges overlap. With nothing changed every remote backend had a median of 9 to 13 seconds; the local cache, which is restored and saved, 24 to 40.

Is a Docker layer cache always faster than no cache?

No. For our Go image only the registry (mode=min) and inline caches had a lower median than building with no cache after a one-line change. A cache helps when the layers it saves are slow to build, as the Python install was, and loses when the changed step is the slow one.

Does mode=max make builds faster than mode=min?

Not in these three images. After a one-line change mode=max was level or slower, and for gha it made the first build slowest, at a median of about 156 seconds for the Node image. Docker says max can get more hits because it caches intermediate stages.

How big is a Docker cache in GitHub Actions?

It depends on the mode and the Dockerfile. For our Go image the registry cache was 47 MB at mode=min and 504 MB at mode=max. The gha and local caches count against GitHub's 10 GB default per repository, and the registry cache does not.

Move your CI onto our runners with one line

Change one line, watch your own build, then decide.

Connect GitHub

Card required. You pay only for the minutes your jobs run.

.github/workflows/ci.yml
jobs: test:removed: runs-on: ubuntu-latestadded: runs-on: runnersio-4vcpu-ubuntu-2604 steps: - uses: actions/checkout@v4 - run: make testadded: build:added: runs-on: runnersio-32vcpu-ubuntu-2604