Skip to content
Ask for a Budget
TechnologyFebruary 23, 20263 min readUpdated on November 11, 2026

Docker layer caching in CI: registry cache or a dedicated runner

How to order your Dockerfile so every change does not invalidate everything, buildx with cache-from and cache-to, local cache risks and ARM64 vs x64.

Docker layer caching in CI: registry cache or a dedicated runner
Índice do artigo
faltam 3 min de leitura

When a pipeline is "slow", the culprit is often a docker build repeating work.

The goal of this post is to leave you with a clear plan to:

  • make your Dockerfile cache-friendly
  • reuse layers across pipelines (through a registry or a dedicated runner)
  • avoid pitfalls on ARM64 and x64

This post is part of the series:

CI/CD series map

The basics that solve 80%: fix the Dockerfile

Layer caching works per Dockerfile instruction.

If you copy the whole repository before installing dependencies, any change invalidates everything.

Recommended pattern:

  1. Copy manifests/lockfiles.
  2. Install dependencies.
  3. Copy the rest of the code.
  4. Build.

Example (Node):

FROM node:24 AS build
WORKDIR /app

COPY package*.json ./
RUN npm ci

COPY . .
RUN npm run build

About the image version (official Node.js schedule, checked on November 11, 2026): Node 20 went out of support on April 30, 2026, so do not use node:20 as a base anymore. Node 24 is in maintenance until April 30, 2028, and Node 26 became active LTS on October 28, 2026. Pin the major version in the tag (node:24, not node:latest) so you do not switch major versions without noticing. The node:24 tag is still republished on every minor and patch update, and each new base image invalidates the cache from the FROM line onward. Docker's documentation points out that tags are mutable and suggests pinning the digest to always get the same image version. Pinning the full version (node:24.x.y) reduces the changes, but that tag is also mutable and can be republished with a new base image. For truly predictable caching, pin the digest (node:24@sha256:...) and update on purpose.

1) What "Docker layer caching" means in CI (in practice)

Layer caching means reusing the results of earlier Docker build steps.

In CI, you only reuse layers consistently when:

  • the runner keeps a local cache (dedicated runner)
  • or you use a remote cache (registry cache)

2) Recommended strategy: registry cache

The idea is simple:

  • --cache-to publishes the cache to the registry
  • --cache-from pulls the cache from the registry on the next run

Conceptual example with BuildKit/buildx:

docker buildx build --push \
  --cache-from=type=registry,ref=registry.example.com/app:buildcache \
  --cache-to=type=registry,ref=registry.example.com/app:buildcache,mode=max \
  -t registry.example.com/app:${GIT_SHA} \
  .

Two details from Docker's documentation. First, mode=max stores every layer, including those from intermediate steps; the default (min) stores only the ones that end up in the final image. max takes more space but tends to hit the cache more often. Second, the registry cache only works with the default docker driver when the containerd image store is enabled; without it, create a builder with another driver (for example, docker buildx create --driver docker-container --use). With that driver, the image only leaves the builder with --push (or --load), which is why the example above uses --push.

3) On dedicated runners: local cache works very well

If you have a dedicated runner (and it is not ephemeral), the Docker daemon can keep layers locally.

Advantages:

  • very fast
  • simple to operate

Risks:

  • a runner shared by many projects "fills up the disk"
  • isolation and security need attention (especially with Docker-in-Docker)

4) ARM64 vs x64 in docker build

If you build images for more than one architecture:

  • builds under emulation are slower
  • caches are not fully reusable across architectures

Good practices:

  • split pipelines (or a matrix) by architecture
  • use buildx multi-arch when it makes sense
  • avoid mixing caches across architectures

Final checklist

  • The Dockerfile copies manifests before the code.
  • Dependencies are installed in a stable layer (the cache gets reused).
  • There is a cache strategy (registry or local).
  • Architecture is part of the strategy (ARM/x64).
  • The build is observable: time before/after and cache hit/miss.

References

Also read

Git CI/CD guide for small teams: performance, cache and runnersWhat is a web app and what are its benefits?Definitive Low-code Guide: What It Is and When to Use It
Previous post
How to speed up CI on GitLab Runner: cache, concurrency and tags
Next post
Dedicated runner: when it pays off and how to plan it in a small team
Newsletter

One email a month, no noise

What we learn shipping custom software and applied AI.

Related articles

Git CI/CD guide for small teams: performance, cache and runners8 min · Technology
What is a web app and what are its benefits?9 min · Technology
Definitive Low-code Guide: What It Is and When to Use It9 min · Technology
How does a software house work?8 min · Technology
Web System: What It Is, How It Works, and the Benefits7 min · Technology

Accelerate your business with X-Apps

Ask for a Budget
X-Apps is an IT provider partner and advised by
Gartner
Receive our e-mails
News on software and applied AI.
Follow X-Apps