Skip to content
Latchkey

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.

buildx
ERROR: failed to solve: the Dockerfile cannot be empty

Common 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

  1. Check the file size and first lines of the Dockerfile in CI.
  2. Ensure it starts with a FROM instruction.
  3. If it is generated, verify the generating step actually wrote content.
Dockerfile
FROM python:3.12-slim
COPY . /app
WORKDIR /app

Point -f at the correct file

If the real Dockerfile lives elsewhere, pass its path so BuildKit reads the right one.

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

Frequently asked questions

What causes ""the Dockerfile cannot be empty""?
The file has no FROM or other instruction, possibly a placeholder that was never filled in or truncated by a bad checkout.
How do I fix "the Dockerfile cannot be empty"?
Confirm the Dockerfile has instructions

Related guides

References

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