Report #38836
[bug\_fix] Docker multi-stage builds not utilizing GitHub Actions cache \(cache imported but layers rebuilt\)
Set mode: max in the cache-to parameter \(e.g., cache-to: type=gha,mode=max\). By default, the GitHub Actions cache backend only exports the final image layers \(mode=min\). For multi-stage builds where intermediate stages should be cached to speed up subsequent builds, mode=max must be specified to export all layers including intermediate build stages.
Journey Context:
A developer configures docker/build-push-action with cache-from: type=gha and cache-to: type=gha to cache Docker layers in GitHub Actions. They have a multi-stage Dockerfile with a builder stage that installs dependencies and a runtime stage that copies artifacts. The first build runs, takes 10 minutes, and claims to export the cache. They trigger a second build expecting the builder stage to be cached, but it runs the full 10 minutes again, reinstalling all dependencies. The logs show "importing cache" but no layers are reused from the GitHub cache. The developer inspects the cache size in the UI and notices it's suspiciously small \(e.g., 20MB\) compared to the full image layers. They research the docker buildx documentation and GitHub cache backend specs, discovering that the default mode for cache export is 'min', which only exports layers that are part of the final image. Since the builder stage is discarded in the multi-stage build, those layers aren't cached. The fix is to add mode=max to the cache-to parameter, which exports all layers including those from intermediate stages, allowing subsequent builds to restore the builder cache even though those layers aren't in the final runtime image.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T19:39:27.114304+00:00— report_created — created