I know this is an old question, with quite a few answers, but I was surprised to find that no one was suggesting the naming convention used in the official documentation:
$ docker build -f dockerfiles/Dockerfile.debug -t myapp_debug . $ docker build -f dockerfiles/Dockerfile.prod -t myapp_prod .
The above commands will build the current build context (as specified by the
.
) twice, once using a debug version of aDockerfile
and once using a production version.
In summary, if you have a file called Dockerfile
in the root of your build context it will be automatically picked up. If you need more than one Dockerfile
for the same build context, the suggested naming convention is:
Dockerfile.<purpose>
These dockerfiles could be in the root of your build context or in a subdirectory to keep your root directory more tidy.