title: How to run Mongo shell command after docker-compose?
body: <p>I would like to start this MongoDB Replica Set:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Wait for those to come up, then access the Mongo shell via terminal:</p>
  
  <pre><code>docker exec -it mongo1 mongo
  </code></pre>
  
  <p>Then in Mongo shell do:</p>
  
  <pre><code>rs.initiate({"_id":"rs0","members":[{"_id":0,"host":"mongo1:27017"},{"_id":1,"host":"mongo2:27017"},{"_id":2,"host":"mongo3:27017"}]})
  </code></pre>
  
  <p>Mongo also allows <code>mongo --eval "rs.initiate(..)"</code>, which may make things easier.</p>
  
  <p>My question is how do I run this command after mongo1, mongo2, mongo3 are up?</p>