135

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?

26 Answers 26

236

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.

8
  • 4
    Oh, I just removed the file extension and it worked well! Thanks so much!
    – helloWORLD
    Nov 24, 2020 at 11:57
  • 6
    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, 2021 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, 2021 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 3, 2022 at 14:20
  • 8
    Just as a reminder, check if you are in the project root directory
    – Baran Yeni
    Apr 19, 2022 at 22:30
28

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
2
  • 1
    ...Well I feel dumb. This isn't my first rodeo with docker, I should've been able to interpret that error. Thanks! Mar 29, 2021 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, 2021 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
1
  • My Dockerfile was on another directory. Moved to same directory and it worked. Thanks.
    – Amrendra
    Apr 7, 2022 at 6:53
14

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
7

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

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
1
  • 1
    I had 2 dots (..) at build instead of one and almost went nuts as none of the other solutions worked... :)
    – benomatis
    Nov 15, 2022 at 23:48
6

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

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.

3

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

1
  • That is a repeat of previous answers. Sep 25, 2022 at 21:26
3

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

Enter image description here

0
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

1
  • 1
    Yes It works with full ABSOLUTE path to Dockerfile
    – anyapps
    Sep 23, 2022 at 7:07
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.

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

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

1
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.

1

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

1

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.

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.

0

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

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.

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.

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.

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.

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.

0

1: Make sure docker file is named Dockerfile without extension. 2: Make sure your at running the command from the location where your Dockerfile is kept.

-2

I met this problem , due to the network problem.

just use an Hongkong server instead, everything goes well~

1
  • How does that answer the question? Sep 25, 2022 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.