We have already talked about using environment files to change your application's behavior. Another way that you can do that is to use multiple Docker Compose files. Each file builds on the previous one, extending it and possibly overriding options. This can give you great flexibility in developing your application or adjusting it to fit different environments. This can be done in one of the following two ways:
The first way is to put your overrides in a file named
docker-compose.override.yml
. This file is read automatically bydocker-compose
. The options indocker-compose.yml
are applied first and then the options indocker-compose.override.yml
are applied.The second option is to use the
-f
flag todocker-compose
. You may include as many compose files as you want. They will be applied in order from left to right. For example, in thedocker-compose -f docker-compose.yml -f docker-compose-prod.yml
command,docker-compose.yml
is read first thendocker-compose-prod.yml...