179

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?

19 Answers 19

332

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.

Sign up to request clarification or add additional context in comments.

11 Comments

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
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.
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 :)
Just as a reminder, check if you are in the project root directory
I fell for exactly the same reason what @BaranYeni wrote. Not being in the project root directoy.
|
36

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 

1 Comment

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).
28

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 Comment

My Dockerfile was on another directory. Moved to same directory and it worked. Thanks.
21

Are you sure about naming your file Dockerfile? it shouldn't be dockerfile nor DockerFile.

Comments

18

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 

Comments

10

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 Comment

I had 2 dots (..) at build instead of one and almost went nuts as none of the other solutions worked... :)
9

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

Comments

3

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.

Comments

3

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

Enter image description here

Comments

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 Comment

Yes It works with full ABSOLUTE path to Dockerfile
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.

Comments

2

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

Comments

2

Most answers talk about the correct way to name the Dockerfile but this problem is caused when the docker build -t vicohq/nodeapp . command is ran outside the development environment. If you use cmd or shell instead of the terminal in the IDE with your Dockerfile, the command won't access your Dockerfile hence the error.

1 Comment

Hi, so would would be the solution? How did you solve it?
0

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

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
0

Note that if you are using Docker Compose with fragments, you cannot partially override the build key. For instance:

 prep: &node build: context: './docker' dockerfile: 'Dockerfile.pnpm' target: 'dev' home: <<: *node build: target: 'home' 

Here, home will not have the custom Dockerfile extension.

Comments

0

I had a slightly different cause for this error today: I'd symlinked a dockerfile from a different directory. Once I changed the symlink to a hard link, docker build runs fine

$ ln -s /path/to/Dockerfile.txt . $ docker image build -f Dockerfile.txt ... ERROR: failed to solve: failed to read dockerfile: open /var/lib/docker/path/to/Dockerfile.txt: no such file or directory $ rm Dockerfile.txt $ ln /path/to/Dockerfile.txt $ docker image build -f Dockerfile.txt ... # no error messages 

Comments

0

It worked for me after deleting the Dockerfile created manually and creating a new one trough CMD running command: type nul > Dockerfile (for Windows Command Prompt)

Comments

-1

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.

Comments

-1

you can try at this

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

works for me on windows

1 Comment

(I find this surprising since the last argument is a directory containing the build context.)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.