Ошибка docker build requires exactly 1 argument

I am trying to build an image from a specific Dockerfile, and tag it at the same time; I am following the online instructions fordocker build, but I get the following error:

«docker build» requires exactly 1 argument(s)

My directory structure:

project/
    foo/
    MyDockerfile

This is the command I run:

docker build -f /full/path/to/MyDockerfile -t proj:myapp

I have tried various combinations of the above command, but the results are always the error message given above. Why is this happening — as I am following what the documentation says?

Community's user avatar

asked Oct 1, 2017 at 21:51

Homunculus Reticulli's user avatar

Parameter -f changes the name of the Dockerfile (when it’s different than regular Dockerfile). It is not for passing the full path to docker build. The path goes as the first argument.

Syntax is:

docker build [PARAMS] PATH

So in your case, this should work:

docker build -f MyDockerfile -t proj:myapp /full/path/to/

or in case you are in the project directory, you just need to use a dot:

docker build -f MyDockerfile -t proj:myapp .

answered Oct 1, 2017 at 21:58

Krzysztof Atłasik's user avatar

5

docker build .

DO NOT MISS «THE DOT».

answered Mar 2, 2021 at 12:02

best wishes's user avatar

0

A. Please upvote Krzysztof’s answer. I was lost without his hints.

But B, my contribution.

I was able to use a full path for the —file argument.

docker build --build-arg JAR_FILE="/source/java/mystuff/build/libs/mything-1.0.10-SNAPSHOT.jar" --file /full/path/to/MyDockerfile -t proj:myapp .

I had forgotten that little «.» at the end.

D’oh!

Aka, do NOT overlook the last little «.» (period) at the end !!!

answered Sep 22, 2020 at 19:45

granadaCoder's user avatar

granadaCodergranadaCoder

25.9k9 gold badges109 silver badges142 bronze badges

0

Docker is a technology that allows you to run applications on top of Linux containers. It enables developers to build, test, and ship code in a more scalable and efficient way. With Docker, organizations can you can do rapid software deployment without changing the current workflow too much. The environment itself is highly portable and was designed with efficiencies that allow you to run multiple Docker containers in a single environment at the same time.

Dockerfile is a text-based configuration file which contains commands that will be used later on to build an image. Using docker build command, users can create an automated build that executes several command-line instructions in succession.

docker: “build” requires 1 argument is an extremely common error messages beginners may face while building an image using the Dockerfile. This article is a compilation of available information about this specific error message as well as how to fix it.

Reproduce “Docker build Requires 1 Argument” error

Let’s take a look at a simple Dockerfile example which contains the following content:

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"]Code language: CSS (css)

What we want to achieve here is fetching CentOS 7 image as the base image, then install unzip and httpd and tries to send ping signal to Google. Obviously, it does not serve any other purpose rather than being a Dockerfile example which also includes a few utility commands.

If we try to build the image using docker build, we should see docker: “build” requires 1 argument error. Below is the full output of the error message:

$ docker build
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage:  docker build [OPTIONS] PATH | URL | -
Build an image from a DockerfileCode language: JavaScript (javascript)

Even if we run docker build with different options, the issue may arise. For example:

$ 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 DockerfileCode language: JavaScript (javascript)

Incorrect docker build arguments

In order to avoid gettting docker: “build” requires 1 argument in the future, we need to get a good grasp at how docker build command works.

The docker build command builds an image from a Dockerfile and a context. The context is a of files at a specified location, either a path or an URL. docker build requires exactly one argument.

Docker only accepts a directory on your local filesystem as PATH and a valid Git repo as URL. Failed to provide either argument may lead to docker: “build” requires 1 argument or other error messages.

Suppose you’re already in the directory where you’ve placed the Dockerfile. In order to fix docker: “build” requires 1 argument add a dot to the command so it becomes docker build . instead of docker build. That way, the build command that uses the current directory (.) as build context.

$ docker build .
Sending build context to Docker daemon  3.054kB
Step 1/4 : FROM        centos:7
14.04: Pulling from library/centos
2e6e20c8e2e6: Extracting [=======>                                      ]  26.86MB/70.69MB
0641a797d01d: Download complete 
516223a864ea: Download complete Code language: JavaScript (javascript)

Alternatively, you can use -f flag followed by a path pointing to the another Dockerfile to build an image.

$ docker build -f /home/user/example/Dockerfile .

The Dockerfile doesn’t have to be named Dockerfile, though. For example, we can use a file named no_Dockerfile.

$ docker build -f /home/user/example/no_Dockerfile .

Don’t forget the dot, especially in build commands with arguments:

$ docker build -t test_image/centos --build-arg JAVA_ENV=1.6  .

We hope that the information above helped you learn a bit more about docker: “build” requires 1 argument error. You may want to check out our tutorials for Docker such as How to fix “docker-compose: command not found, Fix “LookupError: unknown encoding: cp65001” error in Docker and How to install docker and docker-compose on Raspberry Pi.

If you spot an error in the article, please kindly correct us using the comment section below.

docker tutorials

This sneppet shows you how to resolve error “docker build” requires exactly 1 argument. See ‘docker build –help’  that you face while building docker image.

Let’s say you have some source code and Dockerfile in your project directory “myProj” and you are trying to build docker image for the first time and resulted with following error.

~/myProj$ docker build -t sneppets/sshd-example
"docker build" requires exactly 1 argument.
See 'docker build --help'.

Usage:  docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile

Solution

To build an image from Dockerfile you need to use the following docker command.

docker build [OPTIONS] PATH | URL | -

Here we chose to build image with PATH option. Let’s see how to do that.

Build with PATH

To build with PATH you need specify dot “.”, so that all the files in the local project directory myProj get tar’d and sent to the Docker daemon. The PATH used here will find the files for the “context” of the build on the Docker daemon.

Therefore if you are already in to the project directory as shown here “myProj” then you just need to use dot “.” as shown.

$ docker build .

Tag an image with -t

If you want to build a docker image with PATH, repository name (sneppets/sshd-example) and tag (by default latest) then you need to use the following command in case you are in the project directory already. If you don’t mention tag it will take latest by default.

$ docker build -t sneppets/sshd-example .

Note, If you are not in the project directory then you can mention full path instead of dot “.” In our case we are using dot as shown below and could successfully build docker image.

~/myProj$ docker build -t sneppets/sshd-example .
Sending build context to Docker daemon  2.048kB
Step 1/4 : FROM ubuntu
 ---> 4e5021d210f6
Step 2/4 : MAINTAINER sneppets <[email protected]>
 ---> Running in 4ea3abe2dcf5
Removing intermediate container 4ea3abe2dcf5
 ---> f8248d45bbbb
Step 3/4 : RUN apt-get update && apt-get install -y openssh-server
 ---> Running in a26154250cb2
Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB]
Get:3 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [37.0 kB]
Get:4 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [870 kB]
Get:5 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [7904 B]
Get:6 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [835 kB]
------------
------------
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
Removing intermediate container a26154250cb2
 ---> 68b9e843c428
Step 4/4 : RUN mkdir -p /var/run/sshd
 ---> Running in cda475eb7c81
Removing intermediate container cda475eb7c81
 ---> ec1cad7fa3c5
Successfully built ec1cad7fa3c5
Successfully tagged sneppets/sshd-example:latest

Also Read

  • Docker: requested access to the resource is denied ?
  • How to check docker image contents after you pull a docker image
  • Build a Docker Image with a Dockerfile and Cloud Build in GCP?

References

  • docker docs build command
  • ubuntu docs

Introduction

Docker build is a container image builder command. The command helps you to create your container image with some extra tweakable functionalities. While building the image using the “docker build” command beginners face
a very common and simple problem of arguments. In this article, we have discussed various ways of encountering that error and how to resolve the error. Different ways of executing the build are also mentioned in the
article.

Creation of Dockerfile

First of all, we will create a dockerfile. This dockerfile will help us to create a docker container image of the “apache-web-server”. The index page is stored as the default location /usr/local/apache2/htdocs/

Make a directory “TUTORIALSPOINT”.

$mkdir TUTORIALSPOINT

Get inside the “TUTORIALSPOINT” directory, create a file named “Dockerfile”, and open the file with any of the code editors. Here, we used Visual Studio code.

$cd TUTORIALSPOINT $touch Dockerfile $code .

Paste the below Dockerfile codel.

FROM httpd:latest WORKDIR /usr/local/apache2/htdocs/ EXPOSE 80

Different Build Errors

Let us see different build errors we might encounter while creating a container image using the docker build command.

Example 1

If the command is executed inside the “TUTORIALSPOINT” directory where Dockerfile is present.

$pwd

Output

/home/hemant/TUTORIALSPOINT

Now see the build error.

$docker build

Output

"docker build" requires exactly 1 argument. See 'docker build --help'. Usage: docker build [OPTIONS] PATH | URL | - Build an image from a Dockerfile

Example 2

If the command is executed outside the “TUTORIALSPOINT” directory where no Dockerfile is present.

$pwd

Output

/home/hemant

Now see the error.

$docker build

Output

"docker build" requires exactly 1 argument. See 'docker build --help'. Usage: docker build [OPTIONS] PATH | URL | - Build an image from a Dockerfile

Example 3

If the command is executed outside the “TUTORIALSPOINT” directory where no Dockerfile is present.

$pwd

Output

/home/hemant

Now see the error.

$docker build .

Output

unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/hemant/Dockerfile: no such file or directory

Example 4

If the command is executed inside the “TUTORIALSPOINT” directory but the “Dockerfile” is renamed as any other file like “Dockerfile_2”.

$pwd

Output

/home/hemant/TUTORIALSPOINT

Now see the error.

$docker build .

Output

unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/hemant/Dockerfile: no such file or directory

Understand the Build Command

Till now, different build errors are seen. Now understanding the “docker build” command will be best. Below we have a breakdown of all the parts of the command.

The general syntax of the command is −

$docker build [options] [local path or url]

Important options are listed below

File

The default filename of the dockerfile is “Dockerfile” but to change it you can use the “-f” flag. This flag requires the relative path of the dockerfile with the name you have saved it.

Tag

The “-t” flag is used when we want to rename the image that is going to be created using the docker build. This can also be written as “—tag”.

The general syntax to assign tag − name − version If you don’t define the version of the image then docker itself provides a “latest” version.

PATH or Context Directory

This path is a local relative path, it is going to be used by the dockerfile as a reference when executing the commands like COPY and ADD. This path is also known as the “context directory”. Docker daemon first gets the context directory and then finds the files that are required to be copied in the image while building.

URL

If the files that you want to copy are not present on your local system, Instead of the local path just mention the “URL” to the remote directory. For example, you can use a GitHub repository URL.

Implementation Cases

There are various circumstances when building a docker image. Some of the circumstances are mentioned below.

Case 1: Simplest implementation of the “docker build”

Step 1 − Create a directory “TUTORIALSPOINT”

$mkdir TUTORIALSPOINT

Step 2 − Create a dockerfile named “Dockerfile”

$cd TUTORIALSPOINT
$touch Dockerfile

Save the below code in it.

FROM httpd:latest WORKDIR /usr/local/apache2/htdocs/ EXPOSE 80

Open this file and save the below code in it.

Step 3 − Build the docker image

Simplest implementation

$docker build .

Output

Sending build context to Docker daemon 3.072kB Step 1/3 : FROM httpd:latest ---> fe8735c23ec5 Step 2/3 : WORKDIR /usr/local/apache2/htdocs/ ---> Using cache ---> 933e884d81bc Step 3/3 : EXPOSE 80 ---> Using cache ---> a127ab71efab Successfully built a127ab71efab

The image name will be none and it will get an ID. To name the image, use the below command.

$docker build –t image1:version1 .

Output

Sending build context to Docker daemon 3.072kB Step 1/3 : FROM httpd:latest ---> fe8735c23ec5 Step 2/3 : WORKDIR /usr/local/apache2/htdocs/ ---> Using cache ---> 933e884d81bc Step 3/3 : EXPOSE 80 ---> Using cache ---> a127ab71efab Successfully built a127ab71efab Successfully tagged image1:version1

To check the created image.

$docker images

Output

REPOSITORY TAG IMAGE ID CREATED SIZE image1 version1 a127ab71efab 2 days ago 145MB

Case 2: Change the name of the Dockerfile

Follow the below steps for using dockerfile instead of “Dockerfile”.

Step 1: Create a file name as “tutorialfile” with the same dockerfile code as above.

$touch tutorialfile

Step 2: Now build the image using this dockerfile

General syntax: docker build –f complete_path_of_dockerfile –t name:version .

$docker build -f /home/hemant/TUTORIALSPOINT/tutorialfile -t test2:v1 .

Output

Sending build context to Docker daemon 3.584kB Step 1/3 : FROM httpd:latest ---> fe8735c23ec5 Step 2/3 : WORKDIR /usr/local/apache2/htdocs/ ---> Using cache ---> 933e884d81bc Step 3/3 : EXPOSE 80 ---> Using cache ---> a127ab71efab Successfully built a127ab71efab Successfully tagged test2:v1

This will create a docker image from the “tutorialfile”. Check-in created image.

$docker images

Output

REPOSITORY TAG IMAGE ID CREATED SIZE test2 v1 a127ab71efab 2 days ago 145MB

Case 3: Change the Context Directory

In the above examples, we have used the context directory as the “current working directory” by using “dot”.

Step 1: Create a new dockerfile named “newdockerfile”

$touch newdockerfile

Add the below code to the dockerfile.

FROM httpd:latest WORKDIR /usr/local/apache2/htdocs/ RUN rm index.html COPY . . EXPOSE 80

Step 2: Get out of the TUTORIALSPOINT Directory.

First copy the path of the current working directory.

$pwd

Get out of the directory.

$cd ..

Step 3: Now execute the docker build command.

$docker build 
   -f /home/hemant/TUTORIALSPOINT/tutorialfile 
   -t test3:v1 
/home/hemant/TUTORIALSPOINT

Output

Sending build context to Docker daemon 2.56kB Step 1/5 : FROM httpd:latest ---> fe8735c23ec5 Step 2/5 : WORKDIR /usr/local/apache2/htdocs/ ---> Using cache ---> 933e884d81bc Step 3/5 : RUN rm index.html ---> Using cache ---> 0775ee5efabc Step 4/5 : COPY . . ---> ae8dd9f280da Step 5/5 : EXPOSE 80 ---> Running in bccffebf7db2 Removing intermediate container bccffebf7db2 ---> 6261cc2ca031 Successfully built 6261cc2ca031 Successfully tagged test3:v1

Step 4: Now run the container and check if the context directory is set to “home/hemant/TUTORIALSPOINT”

$docker run -itd --name cont -p 8080:80 test3:v1

Step 5: Check if the Context directory is copied on the apache server. Visit the http://localhost:8080/

Hence, the context directory was copied and set well.

Conclusion

Here in this article, we learned the use of the “docker build” command. All the key features of implementing the command in various circumstances were covered. Most importantly, the “context” setting is a well-known doubt in the beginner community.

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account

Closed

sjwl opened this issue

Dec 13, 2018

· 5 comments

Closed

«docker build» requires exactly 1 argument.

#38368

sjwl opened this issue

Dec 13, 2018

· 5 comments

Comments

@sjwl

Description

Steps to reproduce the issue:

  1. cd to location of Dockerfile
  2. docker build

Describe the results you received:
"docker build" requires exactly 1 argument.

Describe the results you expected:
treat docker build as docker build .

Output of docker version:

Client: Docker Engine - Community
 Version:           18.09.0
 API version:       1.39
 Go version:        go1.10.4
 Git commit:        4d60db4
 Built:             Wed Nov  7 00:47:43 2018
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.0
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.4
  Git commit:       4d60db4
  Built:            Wed Nov  7 00:55:00 2018
  OS/Arch:          linux/amd64
  Experimental:     false

@RaviTezu

@thaJeztah

This is by design; docker build requires you to specify the path to build from. Automatically assuming the current directory will be a breaking change, and can result in situations where the location of the build-context was accidentally left out, e.g.

docker build ${ENV_VAR_THAT_WASNT_SET}

So, I don’t think we should change this.

@tonistiigi

@thaJeztah

We could consider improving the error message, and make it less generic (mentioning that the path to the build-context was missing)

@thaJeztah

@RaviTezu if you’re looking for something to work on; this one just came up; #38351 🤗

@thaJeztah

I’ll close this ticket, because of the above, but feel free to continue the conversation.

Понравилась статья? Поделить с друзьями:
  • Ошибка dsc бмв е39
  • Ошибка doc информатика 6 класс скачать
  • Ошибка dsc off mazda 6
  • Ошибка dnserror яндекс браузер как исправить
  • Ошибка dsc e46