Error response from daemon: Dockerfile parse error

2019-06-16 19:24发布

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

标签: docker
5条回答
可以哭但决不认输i
2楼-- · 2019-06-16 20:06

i run docker compose in intellij idea, solved this by remove the number in docker parent folder name.

查看更多
戒情不戒烟
3楼-- · 2019-06-16 20:11

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.

查看更多
不美不萌又怎样
4楼-- · 2019-06-16 20:12

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.

查看更多
走好不送
5楼-- · 2019-06-16 20:13

Solved by removing the dockerfile and creating it with Notepad instead of Visual Code

查看更多
We Are One
6楼-- · 2019-06-16 20:23

While running, appended some text in the start of the file. Removed those using vi in terminal and working fine.

查看更多
登录 后发表回答