docker build_error ai_generated true

failed to solve: failed to compute cache key: failed to calculate checksum of ref

ID: docker/buildkit-cache-key-failed

Also available as: JSON · Markdown
90%Fix Rate
88%Confidence
95Evidence
2022-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
27 active

Root Cause

BuildKit failed to compute cache keys, usually because a COPY/ADD source path doesn't exist in the build context or is excluded by .dockerignore. Also occurs with corrupt BuildKit cache.

generic

Workarounds

  1. 88% success Check .dockerignore to ensure required files are not excluded
    cat .dockerignore
    # Make sure the file referenced in COPY is not matched by any pattern.
    # Common mistake: ignoring 'node_modules' also ignores 'node_modules/.package-lock.json' needed for npm ci

    Sources: https://docs.docker.com/build/building/context/#dockerignore-files

  2. 90% success Verify the build context includes the file and COPY path is relative to context root
    # List files in build context:
    docker build --progress=plain . 2>&1 | head
    # COPY paths are relative to the build context, NOT the Dockerfile location.
    # Use: COPY ./src ./app/src (relative to context root)

    Sources: https://docs.docker.com/build/building/context/

  3. 85% success Clear corrupt BuildKit cache
    docker builder prune --all --force
    # Or remove BuildKit cache directory:
    # rm -rf ~/.local/share/docker/buildkit/

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

Dead Ends

Common approaches that don't work:

  1. Running docker build with --no-cache to bypass the issue 70% fail

    If the source file genuinely doesn't exist in the build context, skipping cache doesn't help. The COPY instruction will still fail.

  2. Switching from BuildKit to legacy builder 80% fail

    Legacy builder is deprecated and will be removed. It may give a different error message but the underlying issue (missing files) remains.

Error Chain

Frequently confused with: