- MainProject
- MyProject
- Dockerfile
- .dockerignore
- MyProject
When I try to build Dockerfile from inside the MyProject
all the contents of dockerignore
are ignored. But if I build from MainProject
folder like docker build -f MyProject/Dockerfile .
Nothing from the dockerignore
is ignored. Can anyone explain where am I going wrong ?
CodePudding user response:
Docker uses something called a build context. This is what you specify here: docker build <PATH-TO-CONTEXT>
. As per the documentation:
Before the docker CLI sends the context to the docker daemon, it looks for a file named .dockerignore in the root directory of the context.
So you need to specify the correct build context for your .dockerignore
file to be read. You can also omit the -f
parameter, if the Dockerfile
is in the root of your build context. So you can just do docker build ./MyProject
from the MainProject
folder and everything should work.