Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error response from daemon: No build stage in current context

Tags:

docker

kvm

Does your dockerfile have a: FROM repo/image

As the first line? I got this error when I forgot to specify the docker image that I was building from.

Even if you're building a "source image" you still need to specify FROM scratch as the first line of the dockerfile.


This usually happens because of the text that is written before the FROM command. Try removing the comments in your dockerfile and build again.

For reference https://github.com/moby/buildkit/issues/164


This message appears when you declare an environment variable (ENV) before declaring FROM.

For example:

# Define variables.
ARG PORT
ENV SERVER_PORT=$PORT

# Install minimal Python 3.
FROM python:3.7-alpine

# Install Python requirements.
COPY requirements.txt /
RUN pip install -r /requirements.txt

# Copy app source code.
COPY src/ /app
...

To resolve this, swap the declarations so that any environment variables are set after FROM.

# Install minimal Python 3.
FROM python:3.7-alpine

# Define variables.
ARG PORT
ENV SERVER_PORT=${PORT}

# Install Python requirements.
COPY requirements.txt /
RUN pip install -r /requirements.txt

# Copy app source code.
COPY src/ /app
...

According to the documentation on docs.docker.com, the first non-comment line of your Dockerfile must be the FROM line. To quote the docs:

The FROM instruction initializes a new build stage and sets the Base Image for subsequent instructions. As such, a valid Dockerfile must start with a FROM instruction.


I had the same issue! What helped me was to have the FROM command as the first command in file:

BAD:

MAINTAINER your name "[email protected]"
FROM dockerimagename

GOOD:

FROM dockerimagename
MAINTAINER your name "[email protected]"

The problem is resolved. When I went to dockerfile to edit the code I noticed that I accidentally uncommented the first line. Stupid mistake, I know. Thank you both for the help.