I would like to start this MongoDB Replica Set:
version: "3"
services:
mongo1:
image: mongo
ports:
- 27017:27017
command: mongod --replSet rs0
mongo2:
image: mongo
ports:
- 27018:27017
command: mongod --replSet rs0
mongo3:
image: mongo
ports:
- 27019:27017
command: mongod --replSet rs0
Wait for those to come up, then access the Mongo shell via terminal:
docker exec -it mongo1 mongo
Then in Mongo shell do:
rs.initiate({"_id":"rs0","members":[{"_id":0,"host":"mongo1:27017"},{"_id":1,"host":"mongo2:27017"},{"_id":2,"host":"mongo3:27017"}]})
Mongo also allows mongo --eval "rs.initiate(..)", which may make things easier.
My question is how do I run this command after mongo1, mongo2, mongo3 are up?