19

I am new to Docker and i am trying to create an image from my application, i created Dockerfile in the same directory with package.json file with no extension, just Dockerfile

Now in Dockerfile:

FROM node:14.16.0
CMD ["/bin/bash"]

and i am trying to build the image with that command

docker build -t app .

But i got this constant error:

[+] Building 0.2s (2/2) FINISHED
 => [internal] load build definition from Dockerfile                                                           0.2s 
 => => transferring dockerfile: 2B                                                                             0.0s 
 => CANCELED [internal] load .dockerignore                                                                     0.0s 
 => => transferring context:                                                                                   0.0s
failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount457647683/Dockerfile: no such file or directory

My folder directory is like this:

   |- Dockerfile
   |- README.md
   |- src
   |- package.json
   |- public
   |- node-modules
   |-package-lock.json

My OS is : Windows 10 Pro

Saher Elgendy
  • 1,519
  • 4
  • 16
  • 27
  • 2
    it works now but i don't know how this happened, i guess i used the docker build command in the wrong directory, i am running the commands from vscode terminals so i guess i didn't run the command in the root directory of the project and where the dockerfile exist, make sure you are in the correct place to run your commands @MarcinWolny – Saher Elgendy Jun 22 '21 at 06:11

7 Answers7

22

I encountered a different issue, so sharing as an FYI. On Windows, I created the docker file as DockerFile instead of Dockerfile. The capital F messed things up.

buddemat
  • 4,552
  • 14
  • 29
  • 49
gallaleo
  • 337
  • 2
  • 3
  • 1
    This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/30833081) – lazylead Jan 20 '22 at 06:28
  • Not only DockerFile to Dockerfile... check the extension even "yml" & "yaml" doesnt support – Bhanu Tez Apr 09 '23 at 08:38
  • 1
    This definitely answers the question I had and search engine directed me to this page. I used the F and got the same error as the OP. – JohnOpincar Apr 12 '23 at 21:12
20

Double check that you are in the right directory. I was in downloads/app

When I downloaded the app from Docker as part of their tutorial, I extracted it and it ended up in downloads/app**/app** Type dir in your terminal to see if you can see dockerfile or another folder called app.

tedtrux
  • 201
  • 2
  • 3
  • I literally facepalmed myself because indeed I was in the wrong directory – antonioACR1 Dec 05 '22 at 17:18
  • In my case I didn't notice that IntelliJ created the project in a subfolder instead of using the supplied directory. So it ended up being in `../project-name/project-name` instead of `../project-name` – Simao Gomes Viana Apr 21 '23 at 14:41
6

If you come here from a duplicate, notice also that Docker prevents you from accessing files outside the current directory tree. So, for example,

docker build -f ../Dockerfile .

will not be allowed. You have to copy the Dockerfile into the current directory, or perhaps run the build in the parent directory.

For what it's worth, you also can't use symlinks to files elsewhere in your file system from docker build for security reasons.

tripleee
  • 175,061
  • 34
  • 275
  • 318
5

Naming convention for Docker file is 'Dockerfile' not 'DockerFile', I got this error because of this.

0

In windows when the Dockerfile is in .txt format I got this error. changing it to type "file" fixed the issue.

  • 1
    I guess you are trying to say you named it `Dockerfile.txt` instead of `Dockerfile`. You could still get away with that if you said `docker build -f Dockerfile.txt .` – tripleee Apr 13 '22 at 03:22
0

It's a pretty generic error message but what caused it for me, was in my Dockerfile, I didn't have a space specifying the initial command properly. Here's how it should look like:

CMD ["command-name"]

Notice the space between "CMD" and "[".

Instead, my mistake was that I typed CMD["command-name"] which resulted in the error you described.

Yann Borie
  • 44
  • 4
0

In my case, the error was that the Dockerfile location was incorrect so I correct the location and it worked

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 18 '23 at 06:28
  • What **exactly** did you do to resolve the problem? What makes you think that this relates to the initial problem? – Nico Haase May 10 '23 at 12:46