BUILDKIT_CACHE_MOUNT cicd build_error ai_generated true

错误:无法求解:无法计算缓存键:无法计算引用 moby::abc123 的校验和:"/some/path":未找到

ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref moby::abc123: "/some/path": not found

ID: cicd/docker-buildkit-cache-mount-error

其他格式: JSON · Markdown 中文 · English
90%修复率
88%置信度
1证据数
2023-11-20首次发现

版本兼容性

版本状态引入弃用备注
Docker 24.0.5 active
Docker 25.0.0 active
BuildKit v0.12.0 active

根因分析

Docker BuildKit 缓存挂载目标路径不存在或无效,通常由于构建上下文中缺少目录或 --mount=type=cache,target= 路径拼写错误。

English

Docker BuildKit cache mount target path does not exist or is invalid, often due to a missing directory in the build context or a typo in the --mount=type=cache,target= path.

generic

官方文档

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

解决方案

  1. Ensure the cache mount target directory exists in the Dockerfile by adding a RUN mkdir -p /some/path before the cache mount instruction.
  2. Use absolute paths and avoid symlinks: change --mount=type=cache,target=/var/cache/apt to a unique path like /cache/apt and ensure no trailing spaces.

无效尝试

常见但无效的做法:

  1. 90% 失败

    Running docker system prune -a removes all cache but doesn't fix the underlying path issue; cache mounts still fail.

  2. 80% 失败

    Adding --no-cache flag forces rebuild but doesn't address the missing directory; error persists on next build.

  3. 50% 失败

    Changing the cache mount from type=cache to type=bind may work but defeats caching purpose and can cause permission issues.