I think I have a possible solution, sharing here for validation/input and in case it helps someone else in the future:
This should apply equally for both RethinkDB and RabbitMQ clusters which follow the pattern of:
- First node that starts is “primary”, is started with a normal command
- All other nodes start as “secondary” and are started with a “–join” (or whatever) parameter which specifies the primary’s address
Create a docker image that has a start script. This script first uses the Meta-Data services from Rancher and looks up its “Service” entry. That result will tell it if there are any other containers in the service. If there aren’t, then run command as primary.
If there are other containers get all their names and generate a Secondary command.
With RethinkDB, it will allow you to specify multiple --join parameters and the first that works will take. The generated command may look something like:
rethinkdb --some option --join db1 --join db2 --join db5
(assuming db1, db2, and db5 are container names returned from the Services Meta-Data call)