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

Diagnose 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.

Terminal
# 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.

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; }

Keep the build context small and deterministic

  • A missing .dockerignore sends node_modules, .git, and build output to the daemon, which is slow and can change layer hashes between environments.
  • A COPY of 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 buildx and QEMU set up explicitly; a plain docker build on an ARM runner silently produces an ARM image.

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 Docker "failed to read dockerfile: no such file or directory" in CI?
There are 3 common causes: no dockerfile at the default location, wrong working directory in ci, and dockerfile excluded or not checked out. Without -f, Docker looks for Dockerfile in the build context root.
How do I fix Docker "failed to read dockerfile: no such file or directory" in CI?
There are 2 fixes depending on which cause you have: pass the explicit dockerfile path and context and confirm the file exists where the build runs. Work through them in order, since the first is the most common.
What does Docker "failed to read dockerfile: no such file or directory" in CI actually mean?
A docker build or docker buildx build fails immediately with failed to read dockerfile: open ...: no such file or directory.
How do I stop Docker "failed to read dockerfile: no such file or directory" in CI happening again?
Always pass -f and the context explicitly in CI builds. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card