151

I am pretty new to Docker and am trying to build a Docker image with plain HTML, but I have this error message, saying

failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount602954594/Dockerfile: no such file or directory

My folder directory is like this:

C:\Users\hailey\Desktop\GitTest
                               |- Dockerfile.txt
                               |- README.md
                               |- testHelloWorld.html

Inside of the Dockerfile, I have

FROM ubuntu
WORKDIR C/Users/hailey/Desktop/GitTest
COPY testHelloWorld.html .
EXPOSE 8080
CMD ["html","testHelloWorld.html"]

I did my command docker build . inside of the directory C:\Users\hailey\Desktop\GitTest and then got:

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

What did I do wrong?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
helloWORLD
  • 1,681
  • 2
  • 5
  • 6

27 Answers27

267

The name of Docker files doesn't have any extension. It's just Dockerfile with capital D and lowercase f.

You can also specify the Dockerfile name, such as docker build . -f Dockerfile.txt if you'd like to name it something else.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Gabriel Petersson
  • 8,434
  • 4
  • 32
  • 41
  • 7
    I got this error even with the correct filename. What saved me was adding the -f Dockerfile, e.g., docker build -t tagname . -f Dockerfile – ormurin Feb 18 '21 at 14:46
  • In my testing, either `dockerfile` or `Dockerfile` with no extension work; anything else needs to be specified with the `-f` flag as in the below answer. – cody.codes May 13 '21 at 14:18
  • thank you! I just got started with Docker and I inadvertently named my file `DockerFile` and started getting the error reported by OP. After changing it to `Dockerfile` as per your enlightening comment, everything started working :) – n0m4d Jan 03 '22 at 14:20
  • if use `docker-compose` set dockerfile: to`Dockerfile` in `docker-compose.yaml` file – Hamed Lohi Feb 27 '22 at 10:04
  • 10
    Just as a reminder, check if you are in the project root directory – Baran Yeni Apr 19 '22 at 22:30
  • Thanks, removing the extension worked. I was using Visual Studio Code and they automatically gave my file the `.dockerfile` extension when I saved it. – Azurespot May 23 '22 at 19:59
  • Thanks, I had named the docker file as DockerFile, so changing the name to Dockerfile worked perfectly. – Shashikiran Neelakantaiah May 25 '22 at 07:30
  • 1
    I fell for exactly the same reason what @BaranYeni wrote. Not being in the project root directoy. – Chris Apr 21 '23 at 05:33
  • That's the true answer. Thank you – iman safari Aug 10 '23 at 15:50
32

One can provide the filename of the Docker file using -f.

For instance, if your Docker file is called Dockerfile.base, call the build command as follows:

docker build . -f Dockerfile.base -t helloworld

Then, you can start the build image using the following command:

docker run --rm -it helloworld
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
koppor
  • 19,079
  • 15
  • 119
  • 161
  • 1
    ...Well I feel dumb. This isn't my first rodeo with docker, I should've been able to interpret that error. Thanks! – Hebe Hilhorst Mar 29 '21 at 19:01
  • 2
    It works because unless you have `dockerfile` or `Dockerfile` as the exact filename (without an extension) you need to specify to docker which file you want to use to build the container when using the `docker build` command. Also important to note you must be in the same directory as you're running the command from for it to work (why I found myself on this question in the first place). – cody.codes May 13 '21 at 14:16
25

I would like to sum up the information from different answers in one answer, and also add my own experience that brought me to this question:

  1. Ensure that you're in the same directory that contains your dockerfile as where you're running your command from (running ls or dir depending on if you're using Linux or Windows/cmd shell respectively to determine if the file you'll use to build your docker container exists there)
  2. Docker will accept at least two (maybe only two?) default names for dockerfiles: dockerfile and Dockerfile. If you have other capitals in the filename it will most likely fail. Also note that the default filenames have no file extension (so if you're to create the file in Notepad for instance, it may be a .txt or another extension by default). There is another answer here that shows how to save it without a filename from notepad, but you can also use the following commands in Linux and Windows command prompt, respectively:
    mv dockerfile.txt dockerfile
    ren dockerfile.txt dockerfile
  3. If you need to use a different name instead of the default dockerfile/Dockerfile, then you can use the option -f (link to docs), which states:

-f, --file string Name of the Dockerfile (Default is 'PATH/Dockerfile')

Taken from another answer, here's an example of how you can use that command:

  docker build . -f Dockerfile.base -t helloworld

And just to bring it all together, you don't need to use the filename again once the container is built, so you can just run it with:

docker run --rm -it helloworld
cody.codes
  • 1,384
  • 1
  • 18
  • 24
16

If you don't really need to use buildkit:

Try to set those .envs before executing your build/Docker composer:

export DOCKER_BUILDKIT=0
export COMPOSE_DOCKER_CLI_BUILD=0
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Raul Medeiros
  • 224
  • 2
  • 5
13

Sorry for hearing that you've an issue. Are you sure about naming your file -> "Dockerfile" ? it shouldn't be "dockerfile" nor "DockerFile"

Ammar Yasser
  • 131
  • 1
  • 2
8

The issue in my case was, the file name was correct, but the extension was txt.

I opened Notepad++ and pasted the FROM mcr.microsoft.com/dotnet/aspnet:3.1 line and after that saved that file from Notepad++ like below.

Enter image description here

Once the file is saved, it will look like below:

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jaydeep Shil
  • 1,894
  • 22
  • 21
6

For those who use docker-compose build also make sure you have properly set build path in docker-compose.yml:

version: '3.8'

services:
  web:
    build: ./services/web/ --> this folder should contain your Dockerfile, otherwise you will have the above error
greenwd
  • 135
  • 1
  • 10
  • 1
    I had 2 dots (`..`) at `build` instead of one and almost went nuts as none of the other solutions worked... :) – benomatis Nov 15 '22 at 23:48
5

I just had this same issue, and it turned out I had to place the Docker file in the right folder—the root project folder.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ifeanyi
  • 51
  • 1
  • 2
3

For me, I just go the root path of project where the Docker file exists.

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pritam
  • 41
  • 1
3

As mentioned before... the issue for me was the Dockerfile name. I had "DockerFile" by accident.

Changing the name to Dockerfile with the lowercase f and rerunning the build command fixed the issue for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jase Kraft
  • 31
  • 2
3

Rename your Dockerfile.txt to just as this Dockerfile. Because the dockerfile has no extensions.

Ahmer Saeed
  • 576
  • 5
  • 13
3

1: Make sure docker file is named "Dockerfile" without any extension.

2: Make sure you are running the command from the location where your Dockerfile is kept.

p kushwaha
  • 327
  • 2
  • 9
2

I got the same error: It could be anything. Mine wasn't anything specific... I had incorrectly named and referenced one of the files in the configurations, so when trying to run build it could not find that file.

It had nothing to do with frontend dockerfile.v0 (totally different file). Check all your file are named and referenced correctly.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
2

Check the name of Dockerfile. It should be "Dockerfile".

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Omer Ahmad
  • 39
  • 2
2

I solved the problem by giving it the full file extension to my Dockerfile

docker build -t testapi . -f [YOUR_FILE_EXTENSION]/Dockerfile

when you give your file extension don't give the relative one give the whole extension such as D:/projects/asp6.0/publish/Dockerfile

Abey Bruck
  • 532
  • 5
  • 7
2

Just be in the same folder where your Dockerfile is located at and run the build command that is how I solved the issue.

1

I had the same issue running "docker build -t getting-started ." from the Visual Studio Code terminal.

But when I've executed the same command in CMD (Windows 10) it worked with no problems.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sabrim
  • 91
  • 8
1

Apart from correcting the Dockerfile name, that error can also happen if you add an extra dot at the end

  • 1
    This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31684307) – Dan May 09 '22 at 19:31
1

I had a similar issue, the error was "no space left on device".

I executed the command: docker system prune and it fixed the problem for me.

Dviros
  • 349
  • 2
  • 3
1

I had the same issue, i solved My case was: in docker-compose.yml i had build->dockerfile: DockerFile while my Dockerfile was f (lowercase)

  • Hi, while your answer seems to address the question, it's substantially a duplicate of the accepted one. While answering, be sure to add some valuable information. Thank you – pierpy Aug 08 '23 at 05:57
0

I ran into a similar issue while building a Visual Studio 2019 generated Docker file:

failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount037306220/dockerfile: no such file or directory

Essentially, the Docker file is being referred from within the Windows Subsystem for Linux (WSL). The tool mounted my local file system and was accessing the Docker file in the context of WSL. As file names are case sensitive on Linux, the Docker command faithfully reported the error:

>> dockerfile: no such file or directory

Renaming the Dockerfile to "dockerfile" resolved the issue.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Eftiquar
  • 29
  • 1
0

Make sure you are in the correct directory first, and docker desktop is running.

Ariel Frischer
  • 1,406
  • 2
  • 12
  • 20
0

I had the same issue working with a React app. I had to move the Dockerfile from src to the project root folder and restarted Docker desktop—it worked.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Isack
  • 1
0

Make sure you see the list using "ls" or "dir" command.

In my case I create Dockerfile using Mac's Textedit and it had a hidden .rtf extension.

After removing the extension it worked.

Homa
  • 134
  • 1
  • 6
0

Another issue I had with this error was around the location in which I was executing the command. It might be useful for some to run the command from the correct directory (where the Dockerfile resides) and include the appropriate naming convention when creating the docker file. Dockerfile.

codeskin
  • 147
  • 1
  • 1
  • 8
0

For me it was wrong directory specification of Dockerfile location. I initially specified parent directory (instead of the subdirectory where actually the Dockerfile was residing) in docker-compose.yml file.

Avik
  • 739
  • 9
  • 15
0

you can try at this

docker build -t testdemo:1.0 .\Dockerfile.txt

works for me on windows

Long tran
  • 71
  • 1
  • 2