Skip to content
Latchkey

Docker "failed to solve: failed to read dockerfile" in CI

BuildKit could not open the Dockerfile it was told to use. The -f/--file path is wrong, the file is not in the build context that was sent, or the default Dockerfile simply does not exist where the build was started.

What this error means

A docker build or docker buildx build fails immediately with failed to solve: failed to read dockerfile. No build steps run because BuildKit never got the instructions to execute.

docker
ERROR: failed to solve: failed to read dockerfile: open Dockerfile: no such file or directory
# or with an explicit -f:
ERROR: failed to solve: failed to read dockerfile: open /var/lib/buildkit/.../Dockerfile.prod: no such file or directory

Common causes

The -f path points at a file that is not there

A -f docker/Dockerfile.prod relative to the wrong working directory, or a typo in the filename, means BuildKit has nothing to read.

The Dockerfile lives outside the build context

The path given to -f must be reachable; when CI checks out a subdirectory or runs from the wrong folder, the expected Dockerfile is simply absent.

Default Dockerfile missing at the context root

A bare docker build . expects a file named Dockerfile at the context root. If it was renamed or moved, the default lookup fails.

How to fix it

Point -f at the real Dockerfile path

Give the exact file path relative to the job working directory and confirm it exists first.

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

Set the build context and file explicitly in Actions

In build-push-action, set both context and file so neither is guessed.

.github/workflows/build.yml
- uses: docker/build-push-action@v6
  with:
    context: .
    file: ./docker/Dockerfile.prod
    push: true
    tags: ghcr.io/myorg/api:1.4.2

How to prevent it

  • Pass an explicit -f/file path rather than relying on the default lookup.
  • List the Dockerfile before building so a wrong path fails loudly.
  • Set context and file together in build-push-action.

Frequently asked questions

What causes ""failed to read dockerfile""?
A -f docker/Dockerfile.prod relative to the wrong working directory, or a typo in the filename, means BuildKit has nothing to read.
How do I fix "failed to read dockerfile"?
Give the exact file path relative to the job working directory and confirm it exists first.

Related guides

References

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