buildx "failed to solve: the Dockerfile cannot be empty" in CI
BuildKit read the Dockerfile it was given and found no instructions in it. The file exists but is empty or contains only blank lines and comments, so there is nothing to build.
What this error means
A build fails immediately with "ERROR: failed to solve: the Dockerfile cannot be empty" even though a Dockerfile path is present.
ERROR: failed to solve: the Dockerfile cannot be emptyCommon causes
An empty or comment-only Dockerfile
The file has no FROM or other instruction, possibly a placeholder that was never filled in or truncated by a bad checkout.
A generated Dockerfile that produced no content
A templating or heredoc step that should write the Dockerfile emitted an empty file, so BuildKit gets nothing.
How to fix it
Confirm the Dockerfile has instructions
- Check the file size and first lines of the Dockerfile in CI.
- Ensure it starts with a
FROMinstruction. - If it is generated, verify the generating step actually wrote content.
FROM python:3.12-slim
COPY . /app
WORKDIR /appPoint -f at the correct file
If the real Dockerfile lives elsewhere, pass its path so BuildKit reads the right one.
docker buildx build -f docker/Dockerfile .How to prevent it
- Commit a non-empty Dockerfile with at least a FROM line.
- Validate generated Dockerfiles are written before building.
- Reference the intended Dockerfile path with
-f.