Working with multiple environments sometimes requires multiple Dockerfiles to some degree. For instance, a dev environment Docker image not necessary be in need of a multi-stage Docker build, where that might not be the case for a production one. You get my point. Most likely, you’ll end up with Dockerfile, Dockerfile-dev, Dockerfile-stage, and suchlike.
docker build . will look for a file named Dockerfile in the current directory before building any image. So, let’s see how to specify a custom one.
- Custom Dockerfile
Step 1. To build a Docker image based on a file named Dockerfile-stage, run the following command:
docker build -f Dockerfile-stage .
Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.