Skip to content
Latchkey

Docker "failed to solve: invalid mount config" (cache id) in CI

A RUN --mount=type=cache accepts an id, target, sharing, and a few other keys. When the mount config is malformed - a missing target, an unknown key, or two mounts fighting over the same id with incompatible sharing - BuildKit rejects it with "invalid mount config".

What this error means

A build with a cache mount fails at the RUN --mount=type=cache step with failed to solve: invalid mount config, naming the bad option or duplicate id.

docker
ERROR: failed to solve: invalid mount config: duplicate mount target "/root/.cache" with conflicting cache id

Common causes

A missing or malformed target

A cache mount with no target= (or a relative target) cannot be resolved to a path inside the build.

Two cache mounts colliding on one id

Two --mount=type=cache declarations sharing an id but using different sharing modes (shared vs locked vs private) conflict.

An unknown mount key

A typo like targt= or an option BuildKit does not recognize makes the whole mount config invalid.

How to fix it

Give each cache mount a valid target and id

  1. Always set an absolute target=.
  2. Use a distinct id= per logical cache, and keep the sharing mode consistent for a given id.
Dockerfile
RUN --mount=type=cache,id=npm,target=/root/.npm,sharing=locked \
    npm ci

Resolve id and sharing conflicts

  1. If two steps mount the same cache, give them the same id and the same sharing mode.
  2. If they should be independent caches, give them different ids.
Dockerfile
# both steps reuse the same Go build cache safely
RUN --mount=type=cache,id=gobuild,target=/root/.cache/go-build,sharing=locked go build ./...
RUN --mount=type=cache,id=gobuild,target=/root/.cache/go-build,sharing=locked go test ./...

How to prevent it

  • Always declare an absolute target= on cache mounts.
  • Keep one sharing mode per cache id across all mounts that use it.

Frequently asked questions

What causes ""invalid mount config""?
A cache mount with no target= (or a relative target) cannot be resolved to a path inside the build.
How do I fix "invalid mount config"?
Give each cache mount a valid target and id

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card