74

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
  • 1
  • 1
Homunculus Reticulli
  • 65,167
  • 81
  • 216
  • 341

6 Answers6

133

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 .

Krzysztof Atłasik
  • 21,985
  • 6
  • 54
  • 76
  • 18
    Thanks for the explanation (+1), strangely enough, I didn't understand it that way when I read the docs - it is a rather unusual way of passing args to a command ... – Homunculus Reticulli Oct 01 '17 at 22:01
  • 1
    If you do "docker build --help" and read "-f" option it says the following : "-f, --file string Name of the Dockerfile (Default is 'PATH/Dockerfile')" PATH is mentioned. – dparkar Sep 08 '18 at 16:08
  • 1
    I forgot the dot at the end. Thanks alot for the extra effort to pinpoint that! – deliciouscookiedev Sep 11 '20 at 12:20
  • 2
    Sooooo, somebody really went out of their way to make this convoluted and over-complicated. What about just letting us use -f to specify file AND path together? ;-) – Markus Bawidamann Feb 24 '21 at 05:53
  • Yes, I also thought that while the default is `PATH/Dockerfile` giving `-f` would override that completely. – juzzlin Mar 08 '21 at 13:49
84

docker build .

DO NOT MISS "THE DOT".

best wishes
  • 5,789
  • 1
  • 34
  • 59
12

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 !!!

granadaCoder
  • 26,328
  • 10
  • 113
  • 146
8

sudo docker build -t my-app .

Don't forget to add DOT at the end.

reference: https://docs.docker.com/get-started/02_our_app/

Soubhagya Kumar Barik
  • 1,979
  • 20
  • 26
0

You can also receive this error if there are spaces in your build arguments. For example:

--build-arg AGENT_BUILDDIRECTORY = $(agent.builddirectory)  

generated the "docker build" requires exactly 1 argument. errors message, and removing the spaces around the equals sign

--build-arg AGENT_BUILDDIRECTORY=$(agent.builddirectory)  

works correctly.

Narthring
  • 1,124
  • 18
  • 32
0

If you're converting your build from a shell script to i.e. gitlab-ci, you might encounter this problem due to different multiline syntaxes:

I.e shell script may have:

 docker build . -t the-something \
  --build-arg COMMIT_SHA=${CI_COMMIT_SHA}

wherease gitlab ci dont need the trailing backslash for multiline:

 script:
- docker build . the-something
  --build-arg COMMIT_SHA=${CI_COMMIT_SHA}

If you keep the trailing backslash, it will be part of the command line and considered an argument.

Brimstedt
  • 3,020
  • 22
  • 32