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.
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
or just in docker build
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.prod.yml docker-compose up --build -f docker-compose.dev.yml
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
which in fact declares just common settings, which will be the same for dev and prod.
Then look at docker-compose.dev.yml, for example I'm using IRIS community edition for development
and docker-compose.prod.yml, and licensed version for testing production environment
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.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.