Меню

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

From the command run:

sudo docker build -t myrepo/redis

there are no «arguments» passed to the docker build command, only a single flag -t and a value for that flag. After docker parses all of the flags for the command, there should be one argument left when you’re running a build.

That argument is the build context. The standard command includes a trailing dot for the context:

sudo docker build -t myrepo/redis .

What’s the build context?

Every docker build sends a directory to the build server. Docker is a client/server application, and the build runs on the server which isn’t necessarily where the docker command is run. Docker uses the build context as the source for files used in COPY and ADD steps. When you are in the current directory to run the build, you would pass a . for the context, aka the current directory. You could pass a completely different directory, even a git repo, and docker will perform the build using that as the context, e.g.:

docker build -t sudobmitch/base:alpine --target alpine-base 
  'https://github.com/sudo-bmitch/docker-base.git#main'

For more details on these options to the build command, see the docker build documentation.

What if you included an argument?

If you are including the value for the build context (typically the .) and still see this error message, you have likely passed more than one argument. Typically this is from failing to parse a flag, or passing a string with spaces without quotes. Possible causes for docker to see more than one argument include:

  • Missing quotes around a path or argument with spaces (take note using variables that may have spaces in them)

  • Incorrect dashes in the command: make sure to type these manually rather than copy and pasting

  • Incorrect quotes: smart quotes don’t work on the command line, type them manually rather than copy and pasting.

  • Whitespace that isn’t white space, or that doesn’t appear to be a space.

Most all of these come from either a typo or copy and pasting from a source that modified the text to look pretty, breaking it for using as a command.

How do you figure out where the CLI error is?

The easiest way I have to debug this, run the command without any other flags:

docker build .

Once that works, add flags back in until you get the error, and then you’ll know what flag is broken and needs the quotes to be fixed/added or dashes corrected, etc.

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

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.

I’ve been working on migrating my the remote jobs platform I built in the past months from weremote.ro to weremote.eu.

The platform’s backend is a GraphQL API built over Express.js which runs inside a Docker container. I was initially building the image myself, whenever I pushed some changes worth deploying to production, but I very quickly switched to GitHub Actions once I learned about this feature.

With this migration to .eu, I also added some features and most importantly, I moved a lot of config into env vars. So before I could actually deploy, I had to update main.workflow which is used by GitHub Actions to define the steps of the build process.

I went on and added the env vars, the secrets, and everything looked right. Except for the fact that I was getting this error when the build was running:

# [...] docker pull logs over here
"docker build" requires exactly 1 argument.
See 'docker build --help'.

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

Build an image from a Dockerfile

### FAILED Build Docker image 13:23:26Z (41.66s)

I thought it was because I had a lot of build args that I was passing at build time.

Basically this:

args = "build --build-arg db_host=${DATABASE_HOST} --build-arg db_user=${DATABASE_USER} --build-arg db_pass=${DATABASE_PASSWORD} --build-arg db_name=${DATABASE_NAME} --build-arg database_authentication_source=${DATABASE_AUTHENTICATION_SOURCE} --build-arg cookie_signing_secret=${COOKIE_SIGNING_SECRET} --build-arg jwt_sign_key=${JWT_SIGN_KEY} --build-arg netlify_build_hook_url=${NETLIFY_BUILD_HOOK_URL} --build-arg mailgun_api_key=${MAILGUN_API_KEY} --build-arg bt_environment=${BT_ENVIRONMENT} --build-arg bt_merchant_id=${BT_MERCHANT_ID} --build-arg bt_public_key=${BT_PUBLIC_KEY} --build-arg bt_private_key=${BT_PRIVATE_KEY} --build-arg bt_merchant_account_id=${BT_MERCHANT_ACCOUNT_ID} -t ${IMAGE_NAME} ."

But as it turns out, my brain works better at 12:30 AM than it works at 2:00 PM.

While I was looking at the values of my env vars, I realised that two variables were storing strings with spaces — bad move.

So here’s an example

$ SOME_ENV_VAR="This is a nice sentence!"
$ docker build --build-arg some_arg=${SOME_ENV_VAR} .

If this happens (and this is what happens when GitHub Actions set your env vars and secrets, you’ll get this error:

[...]
"docker build" requires exactly 1 argument.
See 'docker build --help'.
[...]

That’s because when interpreted the result is your sentence, but without the quotes:

echo $SOME_ENV_VAR
This is a nice sentence!

So when you run your docker build command, and pass the variable as a build argument, it looks like this:

docker build --build-arg some_arg=This is a nice sentence! .

That’s a lot of arguments for docker build which it cannot identify.

And that, folks, is why you get weird errors when running docker build in GitHub Actions.

The solution

  1. You don’t use phrases in your environment variables
  2. You add quotes around those variables
    • docker build --build-arg some_arg='${SOME_ENV_VAR}' .
    • Use single quotes because the whole “build” command is wrapped around with double quotes

Out!

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.

Background

Recently, we need to use dockerfile to build the image. The documents we found are as follows

https://yeasy.gitbooks.io/docker_ practice/content/image/build.html

$ docker build -t nginx:v3 .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM nginx
 ---> e43d811ce2f4
Step 2 : RUN echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html
 ---> Running in 9cdc27646c7b
 ---> 44aa4490ce2c
Removing intermediate container 9cdc27646c7b
Successfully built 44aa4490ce2c

Press the prompt to report an error

$ docker build -t centos_base:v1
"docker build" requires exactly 1 argument.
See 'docker build --help'.

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

Build an image from a Dockerfile

It feels like there’s something fishy going on here~

Resolution

Following the standard process of problem solving  one word at a time, I found a point at the end

Followup

I found this description in the official documentation

https://docs.docker.com/engine/reference/commandline/build/ This example specifies that the PATH is ., and so all the files in the local directory get tard and sent to the Docker daemon. The PATH specifies where to find the files for the “context” of the build on the Docker daemon. Remember that the daemon could be running on a remote machine and that no parsing of the Dockerfile happens at the client side (where you’re running docker build). That means that all the files at PATH get sent, not just the ones listed to ADD in the Dockerfile.

# USAGE
docker build [OPTIONS] PATH | URL | -
# e.g.
docker build .

That is to say, in the official document example, Path indicates . , and then many files in the current directory are sent to the docker’s daemons, Path specifies the path to find files in context when building the image. For example, the first parameter of the Add instruction in dockerfile can be found from the context, that is, the file just sent to docker daemon

Similar Posts:

Docker uses the Dockerfile to build docker images, but what if you want to change the name and (or) the path of this file?
By default “docker build” command uses a file named Dockerfile on the same directory you execute the “docker build“. There is an option to change the path and name of this special file:

  -f, --file string             Name of the Dockerfile (Default is 'PATH/Dockerfile')

And the “-f” may include path and file name but it is mandatory to specify the path at the end “docker build” usually the current directory (context by the docker terminology) by adding “.” (the dot at the end of the command)

So if you want to build with a docker file mydockerfile in the current directory you must execute:

docker build -f mydockerfile .

If your file is in a sub-directory execute:

docker build -f subdirectory/mydockerfile .

The command will create a docker image in your local repository. Here is the output of the first command:

root@srv:~/docker# docker build -f mydockerfile .
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM ubuntu:bionic-20191029
bionic-20191029: Pulling from library/ubuntu
7ddbc47eeb70: Pull complete 
c1bbdc448b72: Pull complete 
8c3b70e39044: Pull complete 
45d437916d57: Pull complete 
Digest: sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d
Status: Downloaded newer image for ubuntu:bionic-20191029
 ---> 775349758637
Step 2/3 : MAINTAINER test@example.com
 ---> Running in 5fa42bca749c
Removing intermediate container 5fa42bca749c
 ---> 0a1ffa1728f4
Step 3/3 : RUN apt-get update && apt-get upgrade -y && apt-get install -y git wget
 ---> Running in 2e35040f247c
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://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
.....
.....
Processing triggers for ca-certificates (20180409) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
Removing intermediate container 2e35040f247c
 ---> 2382809739a4
Successfully built 2382809739a4

Here is the image:

REPOSITORY                            TAG                 IMAGE ID            CREATED              SIZE
root@srv:~# docker images
<none>                                <none>              2382809739a4        About a minute ago   186MB

Build command with custom name and registry URL and TAG

root@srv:~# docker build -t gitlab.ahelpme.com:4567/root/ubuntu-project/ubuntu18-manual-base:v0.1 -f mydockerfile .
Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM ubuntu:bionic-20191029
 ---> 775349758637
Step 2/3 : MAINTAINER test@example.com
 ---> Using cache
 ---> 0a1ffa1728f4
Step 3/3 : RUN apt-get update && apt-get upgrade -y && apt-get install -y git wget
 ---> Using cache
 ---> 2382809739a4
Successfully built 2382809739a4
Successfully tagged gitlab.ahelpme.com:4567/root/ubuntu-project/ubuntu18-manual-base:v0.1
root@srv:~# docker push gitlab.ahelpme.com:4567/root/ubuntu-project/ubuntu18-manual-base:v0.1
The push refers to repository [gitlab.ahelpme.com:4567/root/ubuntu-project/ubuntu18-manual-base]
7cebba4bf6c3: Pushed 
e0b3afb09dc3: Pushed 
6c01b5a53aac: Pushed 
2c6ac8e5063e: Pushed 
cc967c529ced: Pushed 
v0.1: digest: sha256:acf42078bf46e320c402f09c6417a3dae8992ab4f4f685265486063daf30cb13 size: 1364

the registry URL is “gitlab.ahelpme.com:4567” and the project path is “/root/ubuntu-project/” and the name of the image is “ubuntu18-manual-base” with tag “v0.1“. The build command uses the cache from our first build example here (because the docker file is the same).

Typical errors with “-f”

Two errors you may encounter when trying the “-f” to change the name of the default Dockerfile name:

$ docker build -t gitlab.ahelpme.com:4567/root/ubuntu-project/ubuntu18-manual-base:v0.1 -f mydockerfile subdirectory/
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /builds/dev/docker-containers/mydockerfile: no such file or directory

$ docker build -t gitlab.ahelpme.com:4567/root/ubuntu-project/ubuntu18-manual-base:v0.1 -f subdirectory/mydockerfile
"docker build" requires exactly 1 argument.
See 'docker build --help'.

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

First, you might think the -f would take the path and file name and this should be enough, but the errors above appears!

Our example Dockerfile

This is our simple example docker file:

FROM ubuntu:bionic-20191029
MAINTAINER test@example.com

RUN apt-get update && apt-get upgrade -y && apt-get install -y git wget

We are using the official docker image from Ubuntu. Always use official docker images!

Вопрос:

Попытка следовать инструкциям по созданию изображения докеров с сайта докеров.

https://docs.docker.com/examples/running_redis_service/

это ошибка, которую я получаю, следуя инструкциям на документе и используя этот файл Dockerfile

FROM        ubuntu:14.04
RUN         apt-get update && apt-get install -y redis-server
EXPOSE      6379
ENTRYPOINT  ["/usr/bin/redis-server"]


sudo docker build -t myrepo/redis
docker: "build" requires 1 argument. See 'docker build --help'.

Как разрешить?

Лучший ответ:

Вам нужно добавить точку, например docker build -t mytag ., это означает, что вы используете файл Docker в локальном каталоге, а если вы используете docker 1.5, вы можете указать файл Docker otherwhere, извлечь из справки docker build -f, --file="" Name of the Dockerfile(Default is 'Dockerfile' at context root)

Ответ №1

Вы скопировали команду сборки из другого места (веб-страница или какой-либо другой файл)? Попробуйте ввести его с нуля.

Я скопировал команду сборки из учебника AWS и вставил ее в свой терминал и получил эту ошибку. Это сводило меня с ума. После ввода его вручную, это сработало! Подойдя ближе и к моим предыдущим неудачным командам, я заметил, что символ “тире” был другим, он был более тонким, более длинным тире, чем я получил, если сам набрал его с помощью клавиши “минус/тире”.

Плохо:

sudo docker build -t foo.

Хорошо:

sudo docker build -t foo.

Вы видите разницу?.. Вырезать и вставить трудно.

Ответ №2

Используйте следующую команду

docker build -t mytag .

Обратите внимание, что mytag и точка имеют пробел между ними. Эта точка представляет текущий рабочий каталог.

Ответ №3

enter image description here Просто поставьте точку (.) В конце команды, включая один пробел.

пример:

команда: сборка докера -t “blink: v1”.

Здесь вы можете увидеть “blink: v1”, затем пробел, затем точку (.)

Это оно.

Ответ №4


Вам нужна точка в конце…


Так, например:

$ docker build -t <your username>/node-web-app .

Это немного скрыто, но если обратить внимание на . в конце…

Ответ №5

В старых версиях Docker вам нужно использовать этот порядок:

docker build -t tag .

а не

docker build . -t tag

Ответ №6

Вы можете создать образ docker из файла с именем docker file и именем Dockerfile по умолчанию. Он имеет набор команд/инструкций, которые вам нужны в вашем док-контейнере. Ниже команда создает изображение с тегом последний, Dockerfile должен присутствовать в этом месте (. Означает текущую директорию)

docker build . -t <image_name>:latest

Вы можете указать Dockerfile через -f, если имя файла не по умолчанию (Dockerfile) Содержимое файла Sameple Docker.

FROM busybox
RUN echo "hello world"

Ответ №7

Откройте PowerShelland и следуйте этим инструкциям.
Этот тип ошибки типично в Windows S.O.
При использовании командной строки требуется опция и путь.

Существует такой тип ошибки, потому что вы не указали путь к вашему файлу Docker.

Попробуйте следующее:

C:UsersDanieleapp> docker build -t friendlyhello C:UsersDanieleapp
  • friendlyhello – это имя, которое вы назначаете своему участнику
  • C:UsersDanieleapp- это путь, который определяет ваш файл Dockerfile

если вы хотите добавить тег

C:UsersDanieleapp> docker build -t friendlyhello:3.0 C:UsersDanieleapp

Ответ №8

Моя проблема заключалась в том, что Dockerfile.txt нужно было преобразовать в исполняемый файл Unix. Как только я это сделал, эта ошибка ушла.

Возможно, вам придется удалить часть .txt перед этим, но на Mac перейдите в терминал и перейдите в каталог, где находится ваш Dockerfile, и введите

chmod +x "Dockerfile"

И тогда он преобразует ваш файл в исполняемый файл Unix, который затем может быть выполнен командой сборки Docker.

Ответ №9

В моем случае эта ошибка происходила в конвейере Gitlab CI, когда я передавал несколько переменных Gitlab env в docker build --build-arg с --build-arg.

Оказывается, в одной из переменных был пробел, который вызывал ошибку. Его было трудно найти, так как в журналах конвейера просто $VARIABLE_NAME.

Обязательно заключите в кавычки переменные среды, чтобы пробелы обрабатывались правильно.

Меняться от:

--build-arg VARIABLE_NAME=$VARIABLE_NAME

чтобы:

--build-arg VARIABLE_NAME="$VARIABLE_NAME"

Ответ №10

Формат команды сборки Docker

В вашем PowerShell: есть этот тип ошибки, потому что вы не указали путь с вашим Dockerfile.

Попробуй это:

$ docker build -t friendlyhello:latest -f C:\TestDockerApp\Dockerfile.txt

friendlyhello – это имя, которое вы назначаете своему контейнеру и добавляете версию, просто используйте : latest

-f C:TestDockerAppDockerfile.txt – вы хотите добавить тег, потому что команде сборки нужен параметр или тег – DockerFile – это текстовый документ, поэтому явно добавьте расширение .txt

** Попробуйте этот формат:

$ docker build -t friendlyhello:latest -f C:\TestDockerApp\Dockerfile.txt .**

0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ятрогенная патология врачебные ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • Ошибка dnserror яндекс браузер как исправить