Dynamic docker run, within a swarm


I need to be able to to run containers within a swarm for load balancing, but that remove themselves after the run with a -rm.

Now I understand how the swarm works if the container is already running & you are just calling a http port, but i’m struggling to figure out how I can do this with a docker run

Below is a basic example of the run command, that will probably be called from an API.

docker run --rm -ti -v $PWD:$PWD -w $PWD image:tag /bin/bash -c “python script with a variable that changes for each container run”

Any pointers or ideas, would be much appreciated.