Skip to content
Latchkey

Docker "failed to solve: invalid file request" in CI

BuildKit rejected a requested path as invalid. The path referenced by a COPY/ADD, or by -f, points outside the build context or to a location BuildKit will not serve, so the request is refused before the file is read.

What this error means

A build fails with failed to solve: invalid file request <path>, naming a file or directory a step asked for. The path is typically outside the context (a ../ escape) or otherwise unreachable.

docker
ERROR: failed to solve: invalid file request ../shared/config.json
# a COPY tried to reach above the build context root

Common causes

A COPY/ADD escapes the build context

Source paths in COPY/ADD must live inside the context sent to the builder. A ../ that climbs above the context root is an invalid file request.

The -f Dockerfile sits outside the context

When the Dockerfile path resolves outside the build context, BuildKit cannot serve it as a context file and rejects the request.

How to fix it

Keep COPY sources inside the context

Move the needed files under the context, or widen the context to include them.

Terminal / Dockerfile
# instead of COPY ../shared/config.json .
# broaden the context so the file is inside it:
docker build -f service/Dockerfile -t myorg/api:1.4.2 .
# and reference it relative to the context root:
# COPY shared/config.json ./config.json

Use a named additional context for outside files

buildx can mount extra contexts so you do not need ../ escapes.

Terminal
docker buildx build \
  --build-context shared=../shared \
  -t myorg/api:1.4.2 .
# then in the Dockerfile:
# COPY --from=shared config.json ./config.json

How to prevent it

  • Keep all COPY/ADD sources inside the build context.
  • Use --build-context name=path instead of ../ escapes.
  • Set the context root so it contains every file the build needs.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →