# 求解失败：计算缓存键失败：挂载/cache：已在构建阶段挂载

- **ID:** `docker/build-cache-mount-conflict`
- **领域:** docker
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

Dockerfile中的RUN --mount=type=cache指令尝试在同一构建阶段两次挂载相同的缓存目录，导致冲突。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Docker 25.0.3 | active | — | — |
| BuildKit 0.12.5 | active | — | — |

## 解决方案

1. ```
   将两个RUN命令合并为一个使用单一--mount=type=cache的指令，或使用不同的挂载路径：RUN --mount=type=cache,target=/cache/apt ... && ...
   ```
2. ```
   重构Dockerfile，为每个缓存挂载使用单独的构建阶段：FROM base AS builder1使用/cache/apt，然后FROM base AS builder2使用/cache/pip。
   ```

## 无效尝试

- **** — Removing all --mount directives without understanding the conflict loses cache benefits and may break the build. (70% 失败率)
- **** — Using different cache IDs for the same mount path still causes conflict because the path is already mounted. (80% 失败率)
