Would Docker swarm assist me with managing containers with specific environment variables?
Essentially I need to be able to start container with a specific environment variable (an account ID). And I need to run a multiple number of such containers (each with different account IDs).
I’d need to be able to start additional containers, without having to stop the existing containers. I’d also need to be able to stop specific containers. So kind of like a dynamic docker-compose config.
Is Docker swarm something that could assist with the above functionality? Are there other tools (Kubernetes maybe?) alternatively?
Otherwise, if I handled this with the docker-cli, I would start the containers using
docker run passing the relevant environment variable, I’d need to make sure that a container does not already exist with this environment variable and restart the container if it exists.
One Solution collect form web for “Would Docker swarm assist me with managing containers with specific environment variables?”
You can create a new service for each
account ID and pass that information as an environment variable. Here is an example:
docker service create --name service-for-account-123 --env accountId=123 imagename:latest
To stop the containers of this service you can scale it to zero, like this:
docker service scale service-for-account-123=0
To remove all containers you must remove the service:
docker service rm service-for-account-123