BUILDKIT_CACHE_MOUNT_NOT_FOUND cicd build_error ai_generated true

解决失败:无法计算缓存键:无法计算引用'cache-mount-target'的校验和:未找到

failed to solve: failed to compute cache key: failed to calculate checksum of ref 'cache-mount-target': not found

ID: cicd/docker-buildkit-cache-mount

其他格式: JSON · Markdown 中文 · English
90%修复率
83%置信度
1证据数
2024-06-12首次发现

版本兼容性

版本状态引入弃用备注
Docker 25.0 active
BuildKit 0.12.0 active

根因分析

Docker BuildKit缓存挂载目标目录在构建上下文或基础镜像中不存在,导致在Dockerfile中使用`--mount=type=cache,target=/path`时校验和计算失败。

English

Docker BuildKit cache mount target directory does not exist in the build context or base image, causing checksum calculation to fail when using `--mount=type=cache,target=/path` in a Dockerfile.

generic

官方文档

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

解决方案

  1. Create the target directory in the Dockerfile before the cache mount is used: add `RUN mkdir -p /var/cache/apt` before the RUN instruction that uses `--mount=type=cache,target=/var/cache/apt`
  2. Use a different base image that already contains the cache directory, or ensure the directory is included in the build context by creating it locally before build

无效尝试

常见但无效的做法:

  1. 70% 失败

    Removing the cache mount will break the build if the cache is required for package downloads (e.g., apt, npm); the build may fail due to network timeouts or missing dependencies

  2. 50% 失败

    Disabling BuildKit removes cache mount support entirely, and the legacy builder may not support the same Dockerfile syntax, causing a different error