Skip to content

Guides

How to optimise a Dockerfile for CI

Small code changes trigger long rebuilds.

6 min read

Small code changes trigger long rebuilds.

Why it happens

Instruction order defeats the layer cache, and the build context is larger than it needs to be.

How to fix it

  1. Copy the lockfile, install dependencies, then copy source — in that order
  2. Add a .dockerignore covering .git, node_modules and build output
  3. Use multi-stage builds so build tooling stays out of the final image
  4. Use cache mounts for package manager directories rather than caching layers

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.