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.
ERROR: failed to solve: invalid file request ../shared/config.json
# a COPY tried to reach above the build context rootDiagnose it: build context, cache, or platform?
A Dockerfile that builds locally and fails in CI usually differs in one of three ways: the build context contains different files, the layer cache is cold or poisoned, or the runner architecture does not match what the base image provides.
# what is actually being sent as build context (dockerignore applies)
docker build --no-cache --progress=plain -t probe . 2>&1 | head -40
# what platform are you on, and what does the base image support?
docker version --format '{{.Server.Arch}}'
docker buildx imagetools inspect <base-image> | grep -i platform
# prove it is not a cache artefact
docker build --no-cache .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.
# 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.jsonUse a named additional context for outside files
buildx can mount extra contexts so you do not need ../ escapes.
docker buildx build \
--build-context shared=../shared \
-t myorg/api:1.4.2 .
# then in the Dockerfile:
# COPY --from=shared config.json ./config.jsonKeep the build context small and deterministic
- A missing
.dockerignoresendsnode_modules,.git, and build output to the daemon, which is slow and can change layer hashes between environments. - A
COPYof a path that exists locally but is gitignored will fail in CI, because the runner only has what the checkout produced. - Multi-arch builds need
buildxand QEMU set up explicitly; a plaindocker buildon an ARM runner silently produces an ARM image.
How to prevent it
- Keep all COPY/ADD sources inside the build context.
- Use
--build-context name=pathinstead of../escapes. - Set the context root so it contains every file the build needs.