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 directoryCommon 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; }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).