xyzman
xyzman

Reputation: 598

Does Dockerfile always have to be placed in the build context root?

Let's say that I have a Django project and want to create several Dockerfiles which would use different sets of settings and system packages (not to be confused with Python libraries). For the application to run, I have to copy the full project codebase to the image.

Now I've seen Setting up a docker / fig Mesos environment which inspired me to put each separate Dockerfile into its own directory in the project root.

docker build env1/ predictably creates a tarball of env1 and uses it to build the image.

Is there any way I can redefine Dockerfile name or builds context root?

Upvotes: 3

Views: 4414

Answers (1)

Javier Cortejoso
Javier Cortejoso

Reputation: 9156

Docker 1.5 introduced an option to "Specify the Dockerfile to use in build":

Specify the Dockerfile to use in build

Contributed by: Doug Davis – Link to PR

This is possibly one of the most requested feature in the past few months: the ability to specify the file to use in a docker build rather than relying on the default Dockerfile. docker build -f allows you to define multiple Dockerfiles in a single project and specify which one to use at build time. This can be helpful if you require separate Dockerfiles for testing and production environments.

With this feature you don't need to have separated folders for multiple Dockerfiles, so the need of having different folders for each Dockerfile is not need any more. Simply have in your root folder multiple Dockerfiles and build each one with -f option.

Upvotes: 6

Related Questions