Can someone please explain why the answer is not `docker build -f /opt/myapp/Doc .

Adnan K:
can someone please explain why the answer is not docker build -f /opt/myapp/Dockerfile.dev -t webapp Why there is extra /opt/myapp?

Deepak Kumar:
They haven’t mentioned anything about the context in the question but they are using the context directory in the answer.

Aditya Shrivastava:
Usually, the Dockerfile resides along with the project root files. So I think that extra /opt/myapp needs to be there

Adnan K:
so <http://Dockerfile.dev|Dockerfile.dev> is not a Dockerfile here?

Deepak Kumar:
its the dockerfile that’s why we are using -f flag to tell location of docker file and after that its the context location for that docker file

Deepak Kumar:
For example you are in home directory and there is one directory myapp which contains the DockerFile and a react app content so now you will run the the docker build command from your home directory itself without getting inside myapp directory so in that case you will tell the docker daemon that i want to build a docker image from the dockerfile which is inside the myapp directory and all of the required files to build that docker image image is in the myapp directory. so in that case too we have the command " docker build -f myapp/Dockerfile.dev myapp -t reactapp:latest

Deepak Kumar:
myapp
├── http://Dockerfile.dev|Dockerfile.dev
├── requirements.txt
└── reactapp_file

Adnan K:
thank you @Deepak Kumar :+1:

Deepak Kumar:
@Adnan K You are Welcome

Ayush:
Extra /opt/myapp/ is used to define build context i.e. where should docker look for Dockerfile.dev

This is similar to using “.”
With . we tell docker to look for dockerfile at current but currently you are in /tmp so with the extra /opt/myapp you are telling docker to look into /opt/myapp and in this directory look for /opt/myapp/Docker.dev to build image

Sauron:
Read this https://docs.docker.com/engine/reference/commandline/build/#file

>

cd /home/me/myapp/some/dir/really/deep
&gt; docker build -f /home/me/myapp/dockerfiles/debug /home/me/myapp
&gt; docker build -f ../../../../dockerfiles/debug /home/me/myapp

> These two docker build commands do the exact same thing. They both use the contents of the debug file instead of looking for a Dockerfile and will use /home/me/myapp as the root of the build context. Note that debug is in the directory structure of the build context, regardless of how you refer to it on the command line.

Adnan K:
and what is debug file? maybe from real world example?
What I understood so far was that Dockerfile is needed to build images.

Sauron:

They both use the contents of the debug file instead of looking for a Dockerfile

The debug name is just a file name, the file contain contents for Dockerfile commands.

From https://docs.docker.com/engine/reference/commandline/build/
--file -f Name of the Dockerfile (Default is PATH/Dockerfile)