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.
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 directoryCommon 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.
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.
- uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile.prod
push: true
tags: ghcr.io/myorg/api:1.4.2How to prevent it
- Pass an explicit
-f/filepath rather than relying on the default lookup. - List the Dockerfile before building so a wrong path fails loudly.
- Set
contextandfiletogether in build-push-action.