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.

  • Unable to use variable substitution in docker-compose
  • Run command 'node filename.js' inside a Docker container
  • Kubernetes Pod Creation Speed
  • How can I use an ephemeral volume for a Docker container using an official MySQL image with docker-compose?
  • Docker - No route to host
  • How to connect MySQL client with server running in Docker
  • 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.

  • How to convert a Dockerfile to a docker compose image?
  • Build a Simple HTTPServer inside Docker image with Python
  • Unable to register docker selenium remote node to selenium hub remote host with docker
  • ASP.net core dev container
  • Error response from daemon: No such image: ubuntu (tag: latest) right after after pulling from docker hub
  • Executing containers on multiple architectures [closed]
  • 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.