#6418·buildkit

Strange behavior with multiple registry cache-from lines

Author: mtanidaCreated Dec 12, 2025Updated Sep 29, 2026

When using multiple cache-from= lines, what is the expected behavior?

In a CI environment, we might want to have a separate cache for each feature branch. However, we want to mitigate the cold start problem by having a backup cache, usually from the truck (main) branch. So it might look like:

  --cache-from type=registry,ref=${{ env.REGISTRY }}:branch.${{ github.ref_name }}
  --cache-from type=registry,ref=${{ env.REGISTRY }}:main
  --cache-to type=registry,ref=${{ env.REGISTRY }}:branch.${{ github.ref_name }}

However, I've always observed this to behave inconsistently when i test this. Sometimes the build is blazing fast because nothing has changed on the branch, and the branch cache is obviously being used. Other times, the build appears to fall back to using the backup cache, despite nothing having changed in the branch. It actually appears as if the cache is selected at random, and Buildkit simply chooses which ever one it happened to pick.

When I remove the backup cache-from, the first build is slow due to the cold start problem, but subsequent builds are always blazingly fast.

I should add that i am actually using buildx and bake. Doing something like:

bash
docker buildx bake \
  --set "target.cache-from type=registry,ref=${{ env.REGISTRY }}:branch.${{ github.ref_name }}" \
  --set "target.cache-from type=registry,ref=${{ env.REGISTRY }}:main" \
  ...

Perhaps my cache-from arguments are being reordered randomly...

Am I crazy?