BUILDKIT_CACHE_KEY_ERROR cicd build_error ai_generated true

ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref ...: not found

ID: cicd/docker-buildkit-export-failed

Also available as: JSON · Markdown · 中文
82%Fix Rate
88%Confidence
1Evidence
2023-08-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Docker 24.0.5 active
BuildKit 0.12.2 active
Ubuntu 22.04 active

Root Cause

Docker BuildKit cache export fails because the referenced cache layer is missing or corrupted, often due to concurrent builds overwriting the same cache or incomplete cache uploads.

generic

中文

Docker BuildKit 缓存导出失败,因为引用的缓存层丢失或损坏,通常是由于并发构建覆盖了相同的缓存或缓存上传不完整。

Official Documentation

https://docs.docker.com/build/cache/

Workarounds

  1. 85% success Invalidate the specific cache key by adding a unique build argument: docker build --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from type=registry,ref=mycache --cache-to type=registry,ref=mycache,mode=max .
    Invalidate the specific cache key by adding a unique build argument: docker build --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from type=registry,ref=mycache --cache-to type=registry,ref=mycache,mode=max .
  2. 90% success Use a unique cache tag per build (e.g., cache-<commit-sha>) to avoid collision: docker build --cache-from type=registry,ref=myrepo/cache:${GITHUB_SHA} --cache-to type=registry,ref=myrepo/cache:${GITHUB_SHA} .
    Use a unique cache tag per build (e.g., cache-<commit-sha>) to avoid collision: docker build --cache-from type=registry,ref=myrepo/cache:${GITHUB_SHA} --cache-to type=registry,ref=myrepo/cache:${GITHUB_SHA} .
  3. 75% success Clear the remote cache entirely: docker buildx rm mybuilder; docker buildx create --use --driver-opt network=host; then rebuild with fresh cache export.
    Clear the remote cache entirely: docker buildx rm mybuilder; docker buildx create --use --driver-opt network=host; then rebuild with fresh cache export.

中文步骤

  1. Invalidate the specific cache key by adding a unique build argument: docker build --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from type=registry,ref=mycache --cache-to type=registry,ref=mycache,mode=max .
  2. Use a unique cache tag per build (e.g., cache-<commit-sha>) to avoid collision: docker build --cache-from type=registry,ref=myrepo/cache:${GITHUB_SHA} --cache-to type=registry,ref=myrepo/cache:${GITHUB_SHA} .
  3. Clear the remote cache entirely: docker buildx rm mybuilder; docker buildx create --use --driver-opt network=host; then rebuild with fresh cache export.

Dead Ends

Common approaches that don't work:

  1. Rebuilding the entire Docker image without cache (--no-cache) 50% fail

    While this bypasses the cache key error, it defeats the purpose of caching and significantly increases build time; the underlying cache corruption is not fixed.

  2. Manually deleting all Docker cache directories on the runner 80% fail

    Cache may be stored externally (e.g., on a registry or S3); local deletion doesn't fix remote cache corruption.

  3. Increasing the build timeout 95% fail

    The error is not timeout-related; it's a cache integrity issue.