Problem-
I have a docker-compose.yml with 6 services. When i execute docker-compose up, all 6 containers gets started but i need 2 containers to start its work initially and rest 4 containers based on conditions.
Description-
6 services in compose(2 services for all users & 4 services for 2 users):-
-2 service for all users
I'm mounting login required pages in first container
I maintained database for login accounts in 2nd container
-2 services for each users
Is there a way, when i run docker-compose up -it should start only 2 services common to all users and based on the user login i need to start other 2 services where his/her application mounted ???
Doing this based upon user alone would require logic outside of Docker Compose, but you may be able to configure .
You might be able to use two Docker Compose files to accomplish similar results.
In docker-compose.admin.yml
would compliment or override settings in the original compose file, as well as additional containers. You can use overrides to change anything including ENV vars or volumes sent to the containers.
When running docker-compose up
the two services for all users will start.
You can run all six containers by running
docker-compose -f docker-compose.yml -f docker-compose.admin.yml up
Setting up an alias in your .bashrc
would make this much easier to use on a daily basis.
# For regular users
alias comp="docker-compose"
# For two special users
alias comp="docker-compose -f docker-compose.yml -f docker-compose.admin.yml"
With this setup all users can use comp up
or comp down
and get the appropriate set of containers.
See details in the Docker Docs:
Extending Service in Compose
This can now be solved neatly, with a recent addition to docker-compose, compose profiles (at least for the service part, not sure for the volumes). See documentation here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With