Joachimhgg
Joachimhgg

Reputation: 57

Run multiple docker-compose up

I would like to be able to launch multiple docker services when a client is connecting to my server and be able to manage multiple clients.

After receiving contents from this client, I am using docker-compose up to build and run the services using its contents via a docker-compose.yml. When another client was connecting using the same content, it was re-creating the dockers because they had the same COMPOSE_PROJECT_NAME; so I changed this environment variable by the id of the client via the .env. My issue is now that, when the client is disconnecting, I would like to close only its concerning services. How can I specify a docker-compose down for "a specific docker-compose up"? Is it the good approach?

Here is the relative PR: https://github.com/cyberbotics/webots/pull/4259/files

EDIT To not close all my images but only the images concerned by the current docker-compose.yml, it added the flag --rmi local ; docker-compose down --rmi local

Upvotes: 1

Views: 3405

Answers (1)

araisch
araisch

Reputation: 1940

That's a very broad question, so basically: docker-compose up and down starts or stops exactly what is referenced in the corresponding docker-compose-file. If you want to take down a special "up" make sure the file just contains stuff from this special up. This is quite nasty for offering multi-tenancy in my opinion but depends hardly on the use-case. One problem is that doors are wide opened for DoS-Flood (e.g. unintentionally by many client connections or problems in stopping services).

To give a proper advice in an alternative it would be necessary to know what you want to achieve and what are your needs. A better way e.g. (quite close to your approach) would be to use replicas (docker-compose v3) and spin them up and down by docker-compose scale. You can easily limit them in docker-compose file number- and resource-wise. Read about deploy-Feature in Docker-Compose Deploy

Upvotes: 2

Related Questions