How build caches speed up Docker and Expo builds, and the mistakes that undo them

Ravi Menon, Developer tooling editor (AI-assisted) · · updated

Using build caches can drastically reduce build times in development environments. With tools like Docker and Expo, developers can leverage caching to skip unnecessary builds, saving time and resources. Let's explore how much faster these build caches can make your workflows.

Expo's build cache providers: save minutes on each build

Expo's SDK 53 introduces build cache providers that allow developers to skip redundant builds and share caches with teammates, speeding up local development. This caching mechanism leverages shared builds; once a build is compiled, it can be reused rather than recompiling the same code multiple times, enhancing productivity [2].

When you run a command like `npx expo run:ios`, the build cache provider checks for a matching build on a remote server. If it finds one, it downloads and uses that build instead of recompiling. This feature is particularly beneficial for larger applications or when frequently switching branches, as it streamlines the development process [2].

Docker's --cache-from option: efficient in CI/CD

In Continuous Integration/Continuous Deployment (CI/CD) environments, the `--cache-from` option in Docker allows you to use previously built images as cache layers. This is especially useful when builds run independently and don't preserve cache between runs. By specifying older versions of your images as cache sources, you can significantly speed up your builds.

For example, if you pull an older version of your image and build a new one using the `--cache-from` option, Docker can reuse layers from the older image, reducing the need to rebuild everything from scratch. This method ensures that even in CI/CD pipelines, where fresh builds are the norm, you can still take advantage of caching to speed up the process.

Common mistakes to avoid with build caches

While utilizing build caches can enhance your workflow, there are common pitfalls to be aware of:

  1. Inefficient Dockerfile structure: If you place commands that change frequently at the top of your Dockerfile, you risk invalidating the cache for all subsequent layers. Instead, structure your Dockerfile to keep stable layers at the top and frequently changing ones at the bottom. For example, start with commands that install dependencies before copying your application code, as this can allow Docker to cache the installation step unless the dependency files change [1].
  1. Neglecting .dockerignore: Failing to use a `.dockerignore` file can lead to unnecessary files being copied into your image, bloating it and slowing down your builds. Be specific about what files you need in your final image. This practice is akin to packing only the essentials for a trip instead of taking everything from your room—less clutter means a faster and smoother process [1].
  1. Overcomplicating with too many layers: Each layer in your Dockerfile adds complexity. Aim to reduce the total number of layers where possible to minimize cache invalidation. For instance, instead of creating separate layers for each command, you can chain commands together using `&&` to reduce the number of layers created [3].

By addressing these common mistakes, you can maximize the benefits of build caching.

Questions readers ask

How do I set up Docker caching effectively?

To set up Docker caching effectively, ensure your Dockerfile is structured to minimize cache invalidation. Use the `--cache-from` option in CI/CD environments to leverage previously built images.

What are the benefits of using Expo's build cache providers?

Expo's build cache providers allow for skipping redundant builds, which can save several minutes on each build and streamline collaboration among team members.

Can I use caching with multi-stage builds?

Yes, caching can be used with multi-stage builds, but you need to manage your cache layers carefully. Ensure that intermediate images are pushed to a remote registry to optimize caching across builds.

*Corrected 2026-11-20: The headline and first sentence said build caches make Docker builds up to 40 times faster. That figure is a vendor's description of its own remote build service, not a measured effect of caching in general. The headline and first sentence now say what caching does without that figure. Headline was: "Build caches can speed up Docker builds by 40 times".*

Sources

  1. Build Docker images faster using build cache | Depot
  2. Faster local dev with build cache providers in Expo (Experimental)
  3. Speed up your Docker builds with --cache-from | Florin Lipan

More articles