Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Im new to docker and trying to learn it. Im following this tutorial: https://docs.docker.com/get-started/part2/#apppy

So I installed Docker on Windows. Created 3 files, app.py, Dockefile and requirements.txt

My docker file looks like this

# Use an official Python runtime as a parent image
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
CMD ["python", "app.py"]

When I run it in powershell

docker build -t friendlybuild .

But as result it gives this:

Error response from daemon: Dockerfile parse error line 1: unknown instruction: #

Like it doesnt work

I have no idea why it doesnt work

I just tested the same and by default VSCode seems to save the Dockerfile with UTF-16 LE encoding.

Resaving the file as UTF-8 allowed docker build to run without error.

I had an extra line break in my Dockerfile. Didn't even notice it until I read some of these comments and realized it could be a problem. Originally my file was:

FROM openjdk:8
COPY . /usr/src/Main
WORKDIR /usr/src/Main
ENTRYPOINT ["java", "-Xmx700m","-classpath", ".:./resources/:./lib/*",
"org.spark.docker.demo.DockerMultilayerPerceptronClassifier"]

and the error I was seeing was:

$ docker build -t docker-classifier .                                                                                                                                         
Sending build context to Docker daemon  248.3MB
Error response from daemon: Dockerfile parse error line 5: unknown instruction: "ORG.SPARK.DOCKER.DEMO.DOCKERMULTILAYERPERCEPTRONCLASSIFIER"]

Took me a while to figure it out until I read some of these comments above and looked into the line formatting and realized "org.spark.docker.demo.DockerMultilayerPerceptronClassifier"] was on a line of it's own. Once I removed the line break before it everything worked fine. I assumed the parser would ignore it.

# The Dockerfile defines the image's environment
# Import Python runtime and set up working directory
FROM python:2.7-alpine
WORKDIR /app
ADD . /app
# Install any necessary dependencies
RUN pip install -r requirements.txt
# Open port 80 for serving the webpage
EXPOSE 80
# Run app.py when the container launches
CMD ["python", "app.py"]

save the file...

I experienced this issue when working on a React app setup on Docker.

Sending build context to Docker daemon 1.143MB

Error response from daemon: Dockerfile parse error line 1: unknown instruction: +#

Here's how I solved it

The issue was that I had another file named Dockerfile (capital case D) which had some instructions in it, and it was conflicting with the original dockerfile (lower case d) in my project root directory.

I fixed this by deleting the Dockerfile and running the command:

docker build t myapp:latest .

to build the docker image from the dockerfile instead.

That's all.

I hope this helps

Thanks ! I also had a script called "dockerfile" (lowercase d) that was blowing everything up xD Thanks a lot ! – DessM2C Sep 29, 2022 at 22:27

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.