Docker build cache: make slow builds fast with layer order and mounts

Опубликовано: 01 Август 2026
на канале: DeployDevOps
6
0

Your Docker builds probably reinstall every dependency each time you change a single line of code. It is not your machine and it is not Docker being slow. It is layer order, and it is fixable in about a minute.

In this walkthrough we reproduce the slow build on a real project, then apply four fixes on real Dockerfiles with real builds: order your layers so dependencies cache, add a cache mount so your package manager stops re-downloading, and use a multi-stage build to leave the toolchain behind. By the end the same image goes from over 1.5 GB to under 200 MB and rebuilds in seconds.

Full write-up and more DevOps deep-dives at deploydevops.github.io.

Chapters:
00:00 Watch the cache miss happen
00:38 How the layer cache decides
01:14 Copy manifests before source
01:44 Change source, keep the cache
02:15 Cache mounts for your package manager
02:52 Multi-stage to shrink the image
03:23 The payoff: smaller and faster

#docker #dockerfile #docker_build_cache #buildkit #docker_buildx