title: Configuring MongoDB replica set from docker-compose
body: <p>I'm using docker-compose to start 3 MongoDB servers which should be in a replica set.</p>
  
  <p>I first start 3 MongoDB servers, then I configure the replica set.
  This is how I would do the replica set config in a <a href="https://github.com/Icehunter/homebrew-mongodb/blob/master/setup.sh">bash script</a>:</p>
  
  <pre><code>mongo --host 127.0.0.1:27017 &lt;&lt;EOF
  var cfg = {
      "_id": "rs",
      "version": 1,
      "members": [
          {
              "_id": 0,
              "host": "127.0.0.1:27017",
              "priority": 1
          },
  
          // snip...
  
      ]
  };
  rs.initiate(cfg);
  rs.reconfig(cfg)
  EOF
  </code></pre>
  
  <p>Here I'm trying to replicate the configuring of the replica set using <strong>docker-compose</strong>.</p>
  
  <pre><code># docker-compose.yml
  
  mongosetup:
    image: mongo:3.0
    links:
      - mongo1:mongo1
    command: echo 'var cfg = { "_id": "rs", "version": 1, "members": [ { "_id": 0, "host": "127.0.0.1:27017", "priority": 1 }, { "_id": 1, "host": "mongo2:27017", "priority": 1 },{ "_id": 2, "host": "mongo2:27017", "priority": 1 } ] }; rs.initiate(cfg);' | mongo mongo1
  </code></pre>
  
  <p>Unfortunately that creates this error: <code>yaml.scanner.ScannerError: mapping values are not allowed here</code>.</p>
  
  <p>What's the recommended approach?
  Is it possible to store the cfg object in a separate file that docker-compose reads?</p>