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?
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.
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.
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.
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.
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
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:
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)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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With