Docker Containers with unique index

Hi, docker newbie here trying to evaluate how suitable docker is for our use case. I’ve been reading over documentation and it’s still unclear to me whether I can use docker to deploy an application with the properties I would like. In particular, I would like to use docker to launch a network with the following properties:

  • The network is a docker swarm consisting of n processes each running on their own worker node (eventually will be running in AWS)

  • n can be determined when the network is launched (ideally via command line)

  • Each worker, when it is receiving its task to run, is assigned a unique integer ID from 1 to n, and is aware of its ID. Specifically, we will be generating a folder with configuration files for each worker ID and we should be able to determine which configuration folder to copy to a particular instance from its ID.

  • If a worker dies, it is replaced by another worker with the same ID and the same configuration folder

Mostly I am concerned with whether I can achieve the last two bullet points with a convenient workflow (I know I can get the first two easily in the case where all my workers are the same). I realize I can get this by creating n different images each with an environment variable specifying the ID and making each worker its own service, but that requires a docker-compose that scales in size with n and I’d like to do this with a single image and some sort of arguments if at all possible.

Thanks

pass the index as a parameter to the run command, then the container will know.
you could make the folder tree read only, and mapped into the container to allow the container to get its parms.
or just map the indexed folder into the container at a known mount point

I believe you can docker inspect a failed container and retrieve its parm to use on a relaunch