docker,

Build Docker image using custom Dockerfile

Jul 25, 2022 · 1 min read · Post a comment

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.

By default, 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.

Prerequisites

  • Docker
  • Custom Dockerfile

Solution

Step 1. To build a Docker image based on a file named Dockerfile-stage, run the following command:

docker build -f Dockerfile-stage .

Conclusion

Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.