Guides
How to set up Docker layer caching
Docker builds take ten minutes because every layer rebuilds.
7 min read
Docker builds take ten minutes because every layer rebuilds.
Why it happens
There is no persistent layer cache, or the cache is being shipped over the network on every job.
How to fix it
- Use a persistent remote builder so the cache never leaves the machine
- If you must use registry cache, use mode=max to cache intermediate stages too
- Order the Dockerfile so dependencies install before source is copied
- Pin the base image by digest so upstream rebuilds do not invalidate everything
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 optimise a Dockerfile for CISmall code changes trigger long rebuilds.How to use multi-stage Docker buildsImages are large and contain build tooling that should not ship.How to run concurrent Docker builds safelyParallel matrix legs contend and builds slow down or fail.How to use a remote Docker builderThe layer cache is transferred to and from the runner on every build.