Docker "failed to read dockerfile: no such file or directory" in CI
BuildKit could not find the Dockerfile to build. The file path you gave (explicitly with -f, or the default ./Dockerfile) does not exist relative to where the build runs.
What this error means
A docker build or docker buildx build fails immediately with failed to read dockerfile: open ...: no such file or directory. Nothing builds because the recipe itself was not found.
ERROR: failed to solve: failed to read dockerfile: open
/var/lib/docker/.../Dockerfile: no such file or directoryDiagnose 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
No Dockerfile at the default location
Without -f, Docker looks for Dockerfile in the build context root. If it lives in a subdirectory or has a different name (e.g. Dockerfile.prod), the default lookup fails.
Wrong working directory in CI
The build runs from a different directory than expected (a checkout subpath, a monorepo package), so the relative Dockerfile path points nowhere.
Dockerfile excluded or not checked out
A sparse checkout or an over-broad ignore can leave the Dockerfile absent on the runner even though it exists in the repo.
How to fix it
Pass the explicit Dockerfile path and context
Name the Dockerfile and the context separately so neither is guessed.
docker build -f docker/Dockerfile.prod -t myorg/api:1.4.2 ./apiConfirm the file exists where the build runs
List the path from the job’s working directory before building.
pwd && ls -la docker/Dockerfile.prod
test -f docker/Dockerfile.prod || { echo "Dockerfile missing"; exit 1; }Keep 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
- Always pass
-fand the context explicitly in CI builds. - Set the job working directory deliberately in monorepos.
- Ensure the Dockerfile is included in the checkout (no sparse/ignore exclusion).