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.

  • Docker Cache BUNDLE INSTALL not working
  • Channgel Creation Failed. GRPC timeout
  • Using SUID in Alpine Docker Image
  • How to mount a Windows's folder in Docker using Powershell (or CMD)?
  • Docker: unix “who” command doesn't work inside container
  • How to change dockerd parameters with systemd? [duplicate]
  • 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.

  • Building Docker image for a python flask web app. Image does not appear or requirements.txt not found
  • Can't access OpenShift console on http://ip:8443
  • How to export my local docker image to a tar and the load on another computer
  • Responses from kubernetes containers getting lost
  • How can I pull the official images of IBM Container Service?
  • InteliJ Idea: build and run Java apps in docker containers
  • 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
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.