Skip to content
Latchkey

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.

docker build output
ERROR: failed to solve: failed to read dockerfile: open
/var/lib/docker/.../Dockerfile: no such file or directory

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.

Terminal
docker build -f docker/Dockerfile.prod -t myorg/api:1.4.2 ./api

Confirm the file exists where the build runs

List the path from the job’s working directory before building.

Terminal
pwd && ls -la docker/Dockerfile.prod
test -f docker/Dockerfile.prod || { echo "Dockerfile missing"; exit 1; }

How to prevent it

  • Always pass -f and 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).

Frequently asked questions

What causes ""failed to read dockerfile""?
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.
How do I fix "failed to read dockerfile"?
Name the Dockerfile and the context separately so neither is guessed.

Related guides

References

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