Here, in both cases, we faced the issue of “Docker build Requires 1 Argument”.
Before, we move forward to solve the error “Docker build requires 1 Argument”, let’s first understand the Docker build command using different options.
The Docker build is run by the Docker daemon. Firstly Docker build sends the entire context to the daemon.
The ideal situation is to start with an empty directory and add only the files needed to build the Docker image using the Dockerfile:
$ docker build -f /root/dockerImage/Dockerfile .
In order to tag an image, we can use
-t
option with the Docker build command:
$ docker build -t test_image/centos .
We can also pass build arguments with Docker build command:
$ docker build -t test_image/centos --build-arg JAVA_ENV=1.8 .
To clean up the build of an image, we can use
–no-cache
option in the command:
$ docker build -t test_image/centos --build-arg JAVA_ENV=1.8 --no-cache .
In the older version of the Docker, we needed to pass
–no-cache=true
, but it is not in the case of newer versions. We can also create a Dockerfile without having the file name as Dockerfile
:
$ docker build -f /root/dockerImage/DockerFile_JAVA .
Here we created a Docker image using
DockerFile_JAVA
file name.
4. Due to Insufficient Arguments
The most common reason for “Docker build Requires 1 Argument” error is when we try to build the image without providing sufficient arguments.
Here, in the arguments, we need to provide the directory with the command.
By default we provided dot(.) in the command which specifies the Docker daemon to use the shell’s current working directory as the build context:
$ docker build .
The dot(.) basically tells the Docker that Dockerfile has to be used from the current directory. We can also change the Docker build context using the following command:
$ docker build /root/test
Another issue related to Docker build that we may face:
$ docker build -f /root/test/Dockerfile2 .
unable to prepare context: unable to evaluate symlinks in Dockerfile path:
lstat /root/test/Dockerfile2: no such file or directory
Here in the above command, we are trying to build a Docker image using the file name “Dockerfile2”, if this file is not present in the current directory, we will get the following error:
unable to prepare context: unable to evaluate symlinks in Dockerfile path:
lstat /root/test/Dockerfile2: no such file or directory
In order to solve this issue, we need to provide the correct file name with
-f
option.
5. Conclusion
In this tutorial, we learned about the issues related to the Docker build command.
Initially, we explored different ways of building a Docker image, then we addressed the issue with the Docker build arguments, and finally, we learned a few more issues related to the Docker build command.
Authors – All
If you have a few years of experience in the DevOps ecosystem, and you're interested in sharing that experience with the community, have a look at our
Contribution Guidelines
.