6

I just want to build a dockerfile from a different directory, I tried the following command

docker build -f C:/Users/XXXX/XXXX/XXXX/XXXX/XXXX/Dockerfile

and

docker build -f C://Users/XXXX/XXXX/XXXX/XXXX/XXXX/Dockerfile

Both of them yield the same error

"docker build" requires exactly 1 argument.

Am I missing something ?

Ajay Sabarish
  • 171
  • 2
  • 6
  • 1
    You're not passing the required context directory, only the `-f .../Dockerfile` option. The default `-f` value is `Dockerfile` in the named context directory. – David Maze Oct 23 '20 at 14:51
  • @DavidMaze But isn't the `-f PATH` the context directory ? what else should be added ? – Ajay Sabarish Oct 23 '20 at 16:02
  • No, that option specifies a non-default Dockerfile to use; it's separate from the required context-directory option. – David Maze Oct 23 '20 at 18:04

2 Answers2

14

You should provide the context, current directory for instance: ..

docker build -f C://Users/XXXX/XXXX/XXXX/XXXX/XXXX/Dockerfile -t something .

ItayB
  • 10,377
  • 9
  • 50
  • 77
  • 1
    why should we add "." at the end, isn't that what -f string part does ? – Ajay Sabarish Oct 23 '20 at 16:01
  • can you try a single slash after `C:/`? the `.` specify the context, the relative path for your dockerfile. All your commands in the Dockerfile will be relative to this current folder – ItayB Oct 23 '20 at 16:03
  • so through -f we are changing the current folder ? in that case "." is mandatory in every build command ? – Ajay Sabarish Oct 23 '20 at 16:05
  • no, you need `-f if you don't have dockerfile named `Dockerfile` in your current directory. If you will copy that file to your current directory you won't have to specify that and `docker build -t something .` will be enough – ItayB Oct 24 '20 at 09:05
0

It is interpreting the C://Users/XXXX/XXXX/XXXX/XXXX/XXXX/Dockerfile in that line as the value for the -f switch (or option)

If you remove that -f it should rather interpret it as the path to the Dockerfile

when i type docker build at the terminal, i see

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

im not sure what the -f switch does, but when i build images, I am pretty sure I do this

docker image build -t tagname /path/to/Dockerfile