Guides
How to share a Docker cache between jobs
Each matrix leg rebuilds the same layers.
5 min read
Each matrix leg rebuilds the same layers.
Why it happens
Every job gets its own BuildKit instance with an empty cache unless you attach them to a shared builder.
How to fix it
- Attach all jobs to one persistent remote builder
- If using registry cache, have one job populate it and the rest read from it
- Order the Dockerfile so shared layers come first
Your next build could be twice as fast, at half the price
Start free. Migrating away is the same one line, and we publish that diff too.
Related
How to make CI caches actually persistCaches are configured but hit rate is low.How to work around the 10 GB cache limitYour caches exceed 10 GB per repository and start silently evicting.How to share a build cache across repositoriesEach repository maintains its own cache for the same shared dependencies.How to fix Docker cache invalidationDocker layers rebuild even when the relevant files did not change.