. Advertisement .
..3..
. Advertisement .
..4..
An open platform for creating, distributing, and running programs is Docker. You may divide your apps from your infrastructure with the help of Docker, allowing for rapid software delivery. You can control your infrastructure using Docker in the same manner that you manage your applications. “Docker build requires exactly 1 argument” is a common error. In this blog, we will go through some of the ways you can fix this issue. Read on.
When do you get the error “docker build requires exactly 1 argument”?
When you make a brand-new Dockerfile called “Dockerfile” and fill it with the following information:
FROM centos:7
RUN yum -y install wget \
&& yum -y install unzip \
&& yum install -y nc \
&& yum -y install httpd && \
&& yum clean all
EXPOSE 6379
ENTRYPOINT ["ping"]
CMD ["google.com"]
Here, you’ve created a sample Dockerfile using the base image “centos:7.” As a result, it supports all of Centos’ commands. Additionally, you added a few additional Docker utility commands to the Dockerfile. The following command may cause the problem “Docker build Requires 1 Argument” to occur:
$ docker build
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
If you use the Docker build command with other settings, this problem will still arise.
Let’s look at one of the possibilities:
$ docker build -t test_image/centos
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
You have encountered the “docker build requires exactly 1 argument” problem in both of these situations.
How to solve the error “docker build requires exactly 1 argument”?
Solution 1: Use various arguments
Let’s first study the Docker build command using various arguments before moving on to fix the error “Docker build requires 1 Argument”.
The Docker daemon controls the Docker build. First, the daemon receives the whole context from Docker build. Starting with an empty directory and simply adding the files required by the Dockerfile to generate the Docker image is the optimal scenario:
$ docker build .
Sending build context to Docker daemon 2.048kB
Step 1/4 : FROM centos:7
14.04: Pulling from library/centos
2e6e20c8e2e6: Extracting [============> ] 17.83MB/70.69MB
0551a797c01d: Download complete
512123a864da: Download complete
Additionally, you may use the -f flag to point a Dockerfile from a specific place in order to construct an image:
$ docker build -f /root/dockerImage/Dockerfile .
You can use the -t option with the Docker build command to tag an image:
$ docker build -t test_image/centos .
With the Docker build command, you can also pass build arguments:
$ docker build -t test_image/centos --build-arg JAVA_ENV=1.8 .
Use the -no-cache option in the command to tidy up the build of an image:
$ docker build -t test_image/centos --build-arg JAVA_ENV=1.8 --no-cache .
You have to pass -no-cache=true while using an older version of Docker, but not with the more recent ones. You can also construct a Dockerfile that doesn’t have the word “Dockerfile” in the file name:
$ docker build -f /root/dockerImage/DockerFile_JAVA .
Here, you used the DockerFile JAVA file name to construct a Docker image. After doing that, your error will be completely resolved.
Solution 2: Extract the variables
Excepting the solution mentioned above, there is another solution for you to solve the error “docker build requires exactly 1 argument”. It is to extract the variables. Something in those variables is growing to include more than just the flag’s sole argument.
docker build --build-arg "NPM_TOKEN=${NPM_TOKEN}" --tag "$REGISTRY_IMAGE/web-public:$CI_COMMIT_SHA" --tag "$REGISTRY_IMAGE/web-public:$CI_COMMIT_REF_NAME" packages/web-public
To observe how the variables are growing, you may also echo that command, for example:
echo docker build ...
Solution 3: Include a dot
To use the Dockerfile in the local directory, you must include a dot.
For instance:
docker build -t mytag .
It implies that you use the Dockerfile located in your local directory, however Docker 1.5 allows you to specify a Dockerfile located elsewhere. Extract this from the docker build’s help output:
-f, --file="" Name of the Dockerfile(Default is 'Dockerfile' at context root)
Conclusion
In conclusion, we’ve helped you better understand the “docker build requires exactly 1 argument” error and what causes it. Besides, there are 2 simplest solutions for you to manipulate to solve the above error. If you have any difficulties during the operation, or have problems to handle, please leave a comment for us for the earliest support. Thanks for reading!
Read more
→ Solve The Error: “docker.errors.DockerException: Error while fetching server API version”
Leave a comment