compose icon indicating copy to clipboard operation
compose copied to clipboard

Start services based on condition and / or .env file

Open eriksenonline opened this issue 8 years ago • 12 comments

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.

eriksenonline avatar Mar 07 '18 09:03 eriksenonline

Hi @eriksenonline,

That's outside of the scope of Compose and would be best handled by an external script.

shin- avatar Mar 07 '18 16:03 shin-

I would like this kind of feature too, so I open a topic on that subject

boly38 avatar Dec 18 '19 09:12 boly38

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?

piranna avatar Mar 05 '20 07:03 piranna

this would be an awesome extension for our development pipeline. I'm also curious why this is out of scope?

enginaryum avatar Mar 29 '20 12:03 enginaryum

This would be much much better than several docker-compose files. +1

SilvioMachado avatar Nov 03 '20 14:11 SilvioMachado

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?

krysalead avatar Nov 08 '20 20:11 krysalead

Also would appreciate it to conditionally mount a volume based on env var.

porkbrain avatar Nov 25 '20 20:11 porkbrain

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.

renne avatar Jul 26 '23 14:07 renne

That feature would be great!

Gunnnn avatar Jan 31 '24 08:01 Gunnnn

up

underwear avatar Jun 13 '24 22:06 underwear

up

Petrov-Dmitry avatar Aug 27 '24 10:08 Petrov-Dmitry

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/

rltas avatar Nov 15 '24 12:11 rltas