Evgeny Shvarov · Sep 6, 2019

How to have 2 versions of dockerfile for one repository?

Hi Developers!

Suppose I have a project where I want to build an IRIS container with two different dockerfiles depending on goals.  How can I make it?

The issue is that docker-compose is looking for the file with name 'dockerfile'

Are there any #IF constrations in a dockerfile syntax? 

Commenting works but sometimes it's more than one line.



0 204
Discussion (2)1
Log in or sign up to continue

It's actually a very interesting question, and actually mostly depends on what you really want to achieve.

First of all, you can redefine Dockerfile name in docker-compose.yml

version: '3.7'
      context: .
      dockerfile: Dockerfile.test

or just in docker build

docker build -f Dockerfile.test .

But there is another use case when you would need even different docker-compose.yml files. If you would want to split running like in the production and development environment.

You can just do it this way, 

docker-compose up --build -f

docker-compose up --build -f

But I would recommend a bit different way, based on the possibility to extend one YAML file with the content of another.

So we need main docker-compose.yml

version: '3.7'
      file: docker-compose.${MODE:-dev}.yml
      service: iris
      - '${WEBPORT:-52773}:52773'

which in fact declares just common settings, which will be the same for dev and prod.

Then look at, for example I'm using IRIS community edition for development

version: '3.7'
    image: store/intersystems/iris:2019.3.0.302.0-community
      - ./src:/opt/myapp/src

and, and licensed version for testing production environment

version: '3.7'
    image: store/intersystems/iris:2019.3.0.302.0
      - ~/iris.key:/usr/irissys/mgr/iris.key

By default when you will start docker-compose environment, it will use dev. Because here ${MODE:-dev} it uses environment variable MODE with default value as dev. Then, you can change it this way.

MODE=prod docker-compose up --build

But you can also create file .env with values for any environment variables which you would like to redefine. So, in our case it can be like this, with changed WEBPORT as well.


Wow. Thanks Dmitry, this is a real freedom of opportunities.