0

Below is my docker file.

FROM node:6-alpine
EXPOSE 3000
RUN apk add -update tini
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json package.json
RUN npm install && npm cache clean
COPY . .
CMD [ "tini","--","node","./bin/www" ]

I am running this on Windows using a command

docker build -t testnode .

getting below error

Sending build context to Docker daemon  443.4kB
Error response from daemon: failed to parse Dockerfile: file with no instructions.

There are no extra space in my file and Encoding is ANSI.

Darshan Jain
  • 5
  • 1
  • 5
  • would this answer help https://stackoverflow.com/questions/49088933/error-response-from-daemon-dockerfile-parse-error-line-1-unknown-instruction? – Adiii Nov 21 '19 at 15:50
  • My error is different and even I tried those responses too but didn't work – Darshan Jain Nov 21 '19 at 15:59

2 Answers2

0

Try this out -

FROM node:6-alpine
EXPOSE 3000
RUN apk add --update tini
WORKDIR /usr/src/app
COPY package.json package.json
RUN npm install
RUN npm cache clean --force
COPY . .
ENTRYPOINT ["/sbin/tini", "--"]
CMD [ "node", "./bin/www" ]
  • ENTRYPOINT should be defined when using the container as an executable.
  • CMD should be used as a way of defining default arguments for an ENTRYPOINT command or for executing an ad-hoc command in a container.

Here "node" and "./bin/www" are passed as arguments to the "/sbin/tini" executable.

Check out this stackoverflow answer for a detailed understanding of ENTRYPOINT and CMD.

I believe you are taking Docker Mastery tutorial by Bret Fisher. Happy Learning!!

Aditya Mishra
  • 1,687
  • 2
  • 15
  • 24
0

The way I've been able to reproduce this error is to create a Dockerfile that only contains a comment:

$ 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

Note that an empty image, without an entrypoint or cmd, will still build, so trying to fix that with those lines is going to send you the wrong way:

$ more df.scratch 
FROM scratch
LABEL image=scratch

$ docker build -f df.scratch .
[+] Building 0.3s (3/3) FINISHED                                                                         
 => [internal] load build definition from df.scratch                                                0.0s
 => => transferring dockerfile: 76B                                                                 0.0s
 => [internal] load .dockerignore                                                                   0.0s
 => => transferring context: 34B                                                                    0.0s
 => exporting to image                                                                              0.0s
 => => writing image sha256:874d031dd4b7103a9f4159a2bc82c7d21e1885aa477150105d482b3e0462aa7e        0.0s

As for why your file isn't working, it's almost certainly something to do with the encoding of the file. From the CLI rather than the editor, try cat Dockerfile and you should see the file contents, with steps like FROM at the beginning of the lines. If the file appears to be corrupt or missing line feeds, then it's not saved in the correct format. Typically you would use utf-8, ascii should also work, with linefeeds set to the Linux format (LF, not CR-LF).

BMitch
  • 231,797
  • 42
  • 475
  • 450