Full stack web developer, tech lead, project manager
How to use different/multiple docker compose files on different servers ?
There is a page in official documentation that describes this: https://docs.docker.com/compose/extends/
However, this page only describes first 2 options, and completely skips option 3, which is the most versatile and convenient.
It comes down to the following options:
By default, when you execute -
- Docker compose reads two files, a docker-compose.yml and an optional docker-compose.override.yml.
So I might have only docker-compose.yml on my local machine, and docker-compose.yml + docker-compose.override.yml - on my dev/prod servers.
This is not very convenient, and will be difficult to have correct docker-compose.override.yml in my repository, especially when my servers will have differences in setup.
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
This is much better, and I can keep multiple different override files, like docker-compose.prod.yml, docker-compose.dev.yml, etc
But there are 2 problems with the above approach:
docker-compose -f docker-compose.yml -f docker-compose.prod.yml config > docker-compose.stack.yml
This works the same exact way as the above 2 options, except it provides me with the resulting yml file -
, which I can review and check for correctness. Also now I can use this approach in docker swarm.
Now I can use it like:
docker-compose -f docker-compose.stack.yml up -d
Or in swarm:
docker stack deploy -c docker-compose.stack.yml mystack