1

I'm trying to use Docker for the first time for my Django project using the book "Django For Professionals", but I am keep on getting build errors when I type "Docker build ." for a few days. I have looked at other stack overflow posts(An error, "failed to solve with frontend dockerfile.v0") but it still does not work. Here is the error code that I get.

$> docker build .            
[+] Building 0.1s (2/2) FINISHED                                                                                                                                                                            
 => [internal] load build definition from Dockerfile                                                                                                                                                   0.0s
 => => transferring dockerfile: 419B                                                                                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                                                                        0.0s
failed to solve with frontend dockerfile.v0: failed to create LLB definition: file with no instructions

$> export DOCKER_BUILDKIT=0 
export COMPOSE_DOCKER_CLI_BUILD=0

$> docker build .           
Sending build context to Docker daemon  179.2kB
Error response from daemon: failed to parse Dockerfile: file with no instructions 

I have my Dockerfile within my Django project and it is as follows:

FROM python:3.8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

WORKDIR /code
COPY Pipfile Pipfile.lock /code/
RUN pip install pipenv && pipenv install --system

COPY . /code/

I tried cat Dockerfile and here is the output:

yoonjaeseo@Yoons-MacBook-Pro hello % cat Dockerfile
WORKDIR /coderectory 1ECODE 1

COPY . /code/% 

Please let me know if any additional information is needed. Thank you!

BMitch
  • 231,797
  • 42
  • 475
  • 450
Yoon Jae Seo
  • 11
  • 1
  • 4
  • This is not the Dockerfile you wish to use then - what is the name of the actual Dockerfile you want to use? try the build with `-f your.dockerfile` – tymik Jan 30 '22 at 13:08

4 Answers4

1

From the output:

% cat Dockerfile
WORKDIR /coderectory 1ECODE 1

COPY . /code/% 

Your Dockerfile appears to be corrupt, or perhaps saved in the wrong text format. It's likely missing linefeeds (judged by the prompt appearing at the end of the line) which docker needs to parse the file. Make sure you have saved it in utf-8 or ascii text with Linux linefeeds (lf, not cr-lf).

As an example, I'm able to trigger this error with a comment only Dockerfile, and comments end on a linefeed:

$ echo '#' >df.comment

$ docker build -f df.comment .
[+] Building 0.1s (2/2) FINISHED                                                                                                                                                                                   
 => [internal] load build definition from df.comment                                                                                                                                                          0.0s
 => => transferring dockerfile: 45B                                                                                                                                                                           0.0s
 => [internal] load .dockerignore                                                                                                                                                                             0.0s
 => => transferring context: 34B                                                                                                                                                                              0.0s
failed to solve with frontend dockerfile.v0: failed to create LLB definition: file with no instructions

If you can't fix this in your text editor, then run the following from the cli:

cat >Dockerfile <<EOF
FROM python:3.8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

WORKDIR /code
COPY Pipfile Pipfile.lock /code/
RUN pip install pipenv && pipenv install --system

COPY . /code/
EOF
BMitch
  • 231,797
  • 42
  • 475
  • 450
  • The error you're encountering can be found in the parser at https://github.com/moby/buildkit/blob/6b8cea792b7537538b5758eb10de74682e511007/frontend/dockerfile/parser/parser.go – BMitch Jan 30 '22 at 17:05
1

try this, It worked for me

FROM python:3.9-alpine3.13
LABEL maintainer="admin@example.com"

ENV PYTHONUNBUFFERED 1
COPY ./code /code

WORKDIR /code
EXPOSE 8000
RUN python -m venv /py && \
    /py/bin/pip install --upgrade pip && \
    adduser --disabled-password --no-create-home app

ENV PATH="/py/bin:$PATH"
#switches the "root" user to the "app" user
USER app



Djangodev
  • 450
  • 3
  • 17
  • If you wanna use "root" user then the Dockerfile will be ` FROM python:3.9-alpine3.13 LABEL maintainer="admin@example.com" ENV PYTHONUNBUFFERED 1 COPY ./code /code WORKDIR /code EXPOSE 8000 RUN python -m venv /py && \ /py/bin/pip install --upgrade pip ENV PATH="/py/bin:$PATH" ` – Djangodev Jan 30 '22 at 16:39
  • Thank you! This worked for me after I changed the "COPY ./code /code" to "COPY . /code/". However, what I'm worried about is that I use pipenv instead of venv for my virtual enviroment. Will this not be a problem? – Yoon Jae Seo Feb 06 '22 at 07:02
  • @YoonJaeSeo Did you create the build? Is everything ok with that? – Djangodev Feb 07 '22 at 06:01
0

Docker uses the file called Dockerfile by the default when you run docker build ..

In order to use your Dockerfile under a different name you have to specify it as a parameter to the docker build command like:

docker build -f your.custom.dockerfile.name .

it will use your.custom.dockerfile.name as the Dockerfile to build.

tymik
  • 606
  • 7
  • 17
0

You are using multiple docker files at same hierarchy in folder as it looks and have different names. file name should be Dockerfile as this is a standard filename, alternatively different docker file name can be given in command line.

folder1

 --Dockerfile

When you execute docker build, it should run inside folder1. If your requirement is something else, please update the question with more details.

Bijendra
  • 9,467
  • 8
  • 39
  • 66