Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

docker build says there is no build stage in the current context

ErrorError response from daemon: No build stage in current context

Short answer

Every Docker image build needs at least one FROM line, because FROM starts a build stage. The error means the Dockerfile Docker read has none: it is empty, holds only comments or ARG lines, or it is not the file you meant. Print the file Docker actually reads, then fix the file or the -f path.

  • Applies to Docker Engine 28
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the Dockerfile Docker will use, with line numbers. If you pass -f, print that file; otherwise it is the file named Dockerfile at the root of the build context.

    cat -n Dockerfile
  2. 2Match what you see, then jump to its fix

    1. 1The file is empty, or holds only comments, parser directives or ARG linesThe Dockerfile has no FROM instructionFix
    2. 2The Dockerfile you see in the editor has FROM, but the build still failsDocker reads a different file than the one you editedFix

What does the error look like?

  • Error response from daemon: No build stage in current context

Cause 1 of 2

The Dockerfile has no FROM instruction

1Check

A Dockerfile must begin with FROM. Only parser directives, comments and global ARG lines may come before it. An empty file, one saved by mistake, or one where FROM got deleted has no stage at all.

wc -c Dockerfile
grep -n "^FROM" Dockerfile

2Fix

Add a FROM line naming your base image, then the rest of your instructions after it.

FROM node:24
WORKDIR /app
COPY . .
RUN npm ci

3Verify

The build starts and runs the first step.

docker build -t my-app .

Confirmed by docs.docker.com

Did this fix it?

Cause 2 of 2

Docker reads a different file than the one you edited

1Check

Without -f, Docker uses the file named Dockerfile at the root of the build context, which is the PATH argument. In a monorepo or CI job, the context or the -f path can point at another folder, or at an empty file.

pwd
ls -l Dockerfile docker/Dockerfile 2>/dev/null

2Fix

Name the Dockerfile and the context explicitly.

docker build -f docker/Dockerfile -t my-app .

3Verify

The build output starts with the stage from the file you named.

docker build -f docker/Dockerfile -t my-app .

Confirmed by docs.docker.com

Did this fix it?

How do I stop it coming back?

  • Keep one Dockerfile per image in a predictable path and always pass -f and the context in CI.
  • Run docker build in CI on every change so an emptied Dockerfile cannot reach a release.
  • Name stages with FROM ... AS name so later COPY --from and --target refer to something that exists.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.