Skip to content

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

  1. Use a persistent remote builder so the cache never leaves the machine
  2. If you must use registry cache, use mode=max to cache intermediate stages too
  3. Order the Dockerfile so dependencies install before source is copied
  4. 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.