Start services based on condition and / or .env file
In some dev environments, you can have some tools needed on a stag server for profiling, APM testing etc. This can be implemented either in the docker image or as separate containers.
Multiple docker-compose files are not fun to work with. So I wonder if it should be possible to start a service in the docker-compose file based on a variable.
Example In the docker compose on the service we could add a parameter
conditional_startup: true
When this condition is set in the docker-compose it will automatically map to a variable in the .env file.
Then in the .env file we could add this
service_blackfire=true (this will start the service)
service_blackfire=false (this will NOT start the service)
With this, you would not need to maintain complicated CLI commands with -f for another docker-compose file and so on.
Hi @eriksenonline,
That's outside of the scope of Compose and would be best handled by an external script.
I would like this kind of feature too, so I open a topic on that subject
I was looking for just that exactly features too, It would be easy to implement in Docker compose itself, why is It out of scope?
this would be an awesome extension for our development pipeline. I'm also curious why this is out of scope?
This would be much much better than several docker-compose files. +1
I was also wondering if it was possible to start the service conditionally to have a single compose file and then manager with env files the differences, like having a real database or a mock, running the backend only in test mode. I can see valuable use case where this can be used. @shin- can you please elaborate on the fact that it is out of scope?
Also would appreciate it to conditionally mount a volume based on env var.
It would also be great to differentiate between a development and production environment. Additional docker containers like fake SMTP-server, etc. are not needed in the production environment.
That feature would be great!
up
up
Possible workarounds: put it in separate compose files and use COMPOSE_FILE and/or keep it in the main compose file and use COMPOSE_PROFILES in .env. The latter only helps with starting or not starting services while the former can also be used to extend services in different ways.
See https://docs.docker.com/compose/how-tos/environment-variables/envvars/