docker: "build" requires 1 argument. See 'docker build --help'
Asked Answered
I

17

498

Trying to follow the instructions for building a docker image from the docker website.

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

this is the error I get will following the instructions on the doc and using this 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'.

How do resolve?

Infract answered 11/3, 2015 at 20:40 Comment(0)
D
1047

You need to add a dot, which means to use the Dockerfile in the local directory.

For example:

docker build -t mytag .

It means you use the Dockerfile in the local directory, and if you use docker 1.5 you can specify a Dockerfile elsewhere. Extract from the help output from docker build:

-f, --file="" Name of the Dockerfile(Default is 'Dockerfile' at context root)

Desdemona answered 11/3, 2015 at 21:0 Comment(7)
could you please mark the exactly command: "docker build -t mytag ." didn´t see the dotCarafe
@Desdemona I don't agree that . (dot) means local directory, because when using -f (--file) option, putting the . (dot) is still mandatory.Dashtikavir
the . specifies the context of the buildDashtikavir
@andosi zied just adding to your comment that . is the current working directory where the cmd is being executed fromSpringy
Question popularity shows how unclear docker command syntax is ... Personally i thought that dot means just the end of the sentence ...Neodarwinism
Hello from docs.docker.com/get-started/part2/#apppy - I was too blind to see the . there either!Lemoine
Guys, the dot in the command is typical of linux commands, it is not specific of docker command syntax. It might be useful to learn a bit about linux/unix commands.Externalize
D
74

In my case this error was happening in a Gitlab CI pipeline when I was passing multiple Gitlab env variables to docker build with --build-arg flags.

Turns out that one of the variables had a space in it which was causing the error. It was difficult to find since the pipeline logs just showed the $VARIABLE_NAME.

Make sure to quote the environment variables so that spaces get handled correctly.

Change from:

--build-arg VARIABLE_NAME=$VARIABLE_NAME

to:

--build-arg VARIABLE_NAME="$VARIABLE_NAME"
Decennium answered 17/5, 2019 at 22:8 Comment(1)
For me, I was using the --build-arg option, and I was getting this error. I put quotes around my value and that fixed it... It now is run: docker build --build-arg SECRET="${{ secrets.MY_SECRET }}" --tag myRepo/myImage:myTag .Crean
S
54

Did you copy the build command from somewhere else (webpage or some other file)? Try typing it in from scratch.

I copied a build command from an AWS tutorial and pasted it into my terminal and was getting this error. It was driving me crazy. After typing it in by hand, it worked! Looking closer and my previous failed commands, I noticed the "dash" character was different, it was a thinner, longer dash character than I got if I typed it myself using the "minus/dash" key.

Bad:

sudo docker build –t foo .

Good:

sudo docker build -t foo .

Can you see the difference?.. Cut and paste is hard.

Saltillo answered 1/10, 2015 at 3:2 Comment(2)
Thanks bro!! That's exactly what happened to me. And I do not know why, because copied text was the same as what I typed (I checked). Indeed, C&P is hard.Metempsychosis
Was my issue too. Should have higher upvotes as it points out what is likely the most common issueEvertor
B
42

In case anyone is running into this problem when trying to tag -t the image and also build it from a file that is NOT named Dockerfile (i.e. not using simply the . path), you can do it like this:

docker build -t my_image -f my_dockerfile .

Notice that docker expects a directory as the parameter and the filename as an option.

Blaseio answered 19/5, 2020 at 21:38 Comment(3)
Yes! can't use --file without the bottom . dotYaelyager
What the fish, we still need . :( Yeah, it worked.Clustered
Amazing. How did you find out the dot was needed at the end? :)Marte
R
33

Use the following command

docker build -t mytag .

Note that mytag and dot has a space between them . This dot represents the present working directory .

Rumpus answered 20/10, 2016 at 10:2 Comment(0)
L
31

enter image description hereJust provide dot (.) at the end of command including one space.

example:

command: docker build -t "blink:v1" .

Here you can see "blink:v1" then a space then dot(.)

Thats it.

Leishmaniasis answered 25/8, 2018 at 6:53 Comment(1)
in windows also works good with thisWallasey
C
23


You Need a DOT at the end...


So for example:

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

It's a bit hidden, but if you pay attention to the . at the end...

Cloddish answered 10/7, 2018 at 5:39 Comment(2)
You saved my day. Thanks you.Executant
It is not necessarily the current directory ('dot' symbol). It is just the build context for dockerfile.Implantation
V
10

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.

Vociferous answered 23/10, 2020 at 16:28 Comment(0)
S
5

On older versions of Docker it seems you need to use this order:

docker build -t tag .

and not

docker build . -t tag

Sisterly answered 16/5, 2017 at 22:5 Comment(0)
E
4

You can build docker image from a file called docker file and named Dockerfile by default. It has set of command/instruction that you need in your docker container. Below command creates image with tag latest, Dockerfile should present on that location (. means present direcotry)

docker build . -t <image_name>:latest

You can specify the Dockerfile via -f if the file name in not default (Dockerfile) Sameple Docker file contents.

FROM busybox
RUN echo "hello world"
Eisk answered 8/12, 2018 at 18:19 Comment(0)
G
3

Open PowerShelland and follow these istruction. This type of error is tipically in Windows S.O. When you use command build need an option and a path.

There is this type of error becouse you have not specified a path whit your Dockerfile.

Try this:

C:\Users\Daniele\app> docker build -t friendlyhello C:\Users\Daniele\app\
  1. friendlyhello is the name who you assign to your conteiner
  2. C:\Users\Daniele\app\ is the path who conteins your Dockerfile

if you want to add a tag

C:\Users\Daniele\app> docker build -t friendlyhello:3.0 C:\Users\Daniele\app\
Goodly answered 25/7, 2017 at 15:53 Comment(0)
R
2

The following command worked for me. Docker file was placed in my-app-master folder.

docker build -f my-app-master/Dockerfile -t my-app-master .

Readable answered 7/3, 2020 at 12:8 Comment(0)
U
1

My problem was the Dockerfile.txt needed to be converted to a Unix executable file. Once I did that that error went away.

You may need to remove the .txt portion before doing this, but on a mac go to terminal and cd into the directory where your Dockerfile is and the type

chmod +x "Dockerfile"

And then it will convert your file to a Unix executable file which can then be executed by the Docker build command.

Uam answered 11/2, 2019 at 20:30 Comment(0)
C
1

In my case I was using a dash (slightly longer hyphen) symbol – before the t option was the problem.

docker build –t simple-node .

Replace with a hyphen/ minus symbol.

docker build -t simple-node .
Coven answered 30/8, 2022 at 16:51 Comment(0)
F
0
#Using a file other than Dockerfile instead.
#Supose my file is `Dockerfile-dev`

docker build -t mytag - < Dockerfile-dev

Forelady answered 11/7, 2022 at 18:58 Comment(1)
In most cases this construction is wrong. Since there's no build-context directory, you can't COPY anything into the image, which is an issue for most practical images.Danyelledanyette
M
0

I got this error when using Docker with Jenkins pipeline within a pipeline script. The solution was to use this syntax in the pipeline script:

docker.build("[my_docker_image_tag]", "-f ./path/to/my/Dockerfile.jvm .")
Methinks answered 25/9, 2022 at 13:31 Comment(0)
K
-3

Docker Build Command Format

In your powershell : There is this type of error because you have not specified a path whith your Dockerfile.

Try this:

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

friendlyhello is the name you assign to your container and add the version , just use the :latest

-f C:\TestDockerApp\Dockerfile.txt - you want to add a tag because the build command needs a parameter or tag - The DockerFile is a text document so explicitly add the extension .txt

**Try this format :

$ docker build -t friendlyhello:latest -f C:\\TestDockerApp\\Dockerfile.txt .**
Krusche answered 30/7, 2018 at 12:36 Comment(1)
The command you've provided should fail with the same error. You must include a build context as an argument, often a . to indicate the current directory should be sent to the docker engine as the build context.Vociferous

© 2022 - 2024 — McMap. All rights reserved.