# failed to solve: failed to compute cache key: mount /cache: already mounted in build stage

- **ID:** `docker/build-cache-mount-conflict`
- **Domain:** docker
- **Category:** build_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

A RUN --mount=type=cache directive in Dockerfile tries to mount the same cache directory twice in the same build stage, causing a conflict.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Docker 25.0.3 | active | — | — |
| BuildKit 0.12.5 | active | — | — |

## Workarounds

1. **Merge the two RUN commands into one that uses a single --mount=type=cache, or use different mount paths: RUN --mount=type=cache,target=/cache/apt ... && ...** (85% success)
   ```
   Merge the two RUN commands into one that uses a single --mount=type=cache, or use different mount paths: RUN --mount=type=cache,target=/cache/apt ... && ...
   ```
2. **Restructure Dockerfile to use separate stages for each cache mount: FROM base AS builder1 with /cache/apt, then FROM base AS builder2 with /cache/pip.** (80% success)
   ```
   Restructure Dockerfile to use separate stages for each cache mount: FROM base AS builder1 with /cache/apt, then FROM base AS builder2 with /cache/pip.
   ```

## Dead Ends

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