Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

failed to solve with frontend dockerfile

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?

like image 565
helloWORLD Avatar asked Nov 24 '20 11:11

helloWORLD


People also ask

What is docker Buildx?

Docker Buildx is a CLI plugin that extends the docker command with the full support of the features provided by Moby BuildKit builder toolkit. It provides the same user experience as docker build with many new features like creating scoped builder instances and building against multiple nodes concurrently.

What is Docker_buildkit?

BuildKit works on multiple export formats such as OCI or Docker along with the Support of Frontends (Dockerfile) and provides features such as efficient caching and running parallel build operations. BuildKit only needs container runtime for its execution and currently supported runtimes include containerd and runc.

What is docker build context?

The docker build command builds Docker images from a Dockerfile and a “context”. A build's context is the set of files located in the specified PATH or URL . The build process can refer to any of the files in the context. For example, your build can use a COPY instruction to reference a file in the context.


3 Answers

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.

like image 189
Gabriel Petersson Avatar answered Nov 08 '22 17:11

Gabriel Petersson


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
like image 27
koppor Avatar answered Nov 08 '22 17:11

koppor


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
like image 27
cody.codes Avatar answered Nov 08 '22 17:11

cody.codes