failed to solve with frontend dockerfile

Viewed 171318

I am pretty new to Docker and trying to build 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. 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

Does anyone have any other what I did wrong?

21 Answers

The name of docker files has no 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

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 following command:

docker run --rm -it helloworld

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

You really need to use buildkit? if not:

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

export DOCKER_BUILDKIT=0
export COMPOSE_DOCKER_CLI_BUILD=0

The issue in my case was, file name was correct but the extension was txt. What I did is , opened notepad++ and pasted this 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

I just this same issue, turned out I had to place the docker file in right folder--the root project folder.

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

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 configs 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 name and referenced correctly.

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

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

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

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

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

I ran into 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 is accessing the docker file in 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.

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

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

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

I had the same issue Working with react app. I had to move the Dockerfile from src to the project root folder and restarted docker desktop...it worked.

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.

Check the name of Dockerfile it should be "Dockerfile"

For me I just go the root path of project where docker file is exist.

enter image description here

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.

I met this problem , due to the network problem.

just use an Hongkong server instead, everything goes well~

Related