Docker swarm mode with replicas: how to know container name inside

Not sure if it would work but based on Unique ENV var value per swarm replica instance you can try the following

environment:
- SLOT={{.Task.Slot}}

Which I am thinking that Slot is the replica number.