How do you make Docker builds fast in CI where runners are ephemeral?
BeginnerProductionBuild Performance & CI
Answer
Export and import the BuildKit cache from a registry or CI cache backend.
docker buildx build \
--cache-from type=registry,ref=reg.example.com/app:buildcache \
--cache-to type=registry,ref=reg.example.com/app:buildcache,mode=max \
-t reg.example.com/app:$GIT_SHA --push .
mode=max also caches intermediate stages. On GitHub Actions use type=gha.
More on Build Performance & CI
What are the cache backends in buildx?BeginnerWhy does `inline` cache often disappoint?AdvancedHow do you structure a Python Dockerfile for the best caching and size?IntermediateHow do you structure a Node.js production image?IntermediateHow do you build a small Java image?BeginnerHow do you build a Go image under 15 MB?Beginner