title: How to Initialize a Collection in Dockerized Mongo DB
body: <p>Here below is the <code>docker-compose.yml</code> I use to dockerize my MongoDB instance:</p>
  
  <pre><code>version: '3.3'
  
  services:
    mongo:
      image: 'mongo:latest'
      ports:
        - '27017:27017'
      volumes:
        - 'data-storage:/data/db'
      networks:
        mynet:
  
  volumes:
    data-storage:
  
  networks:
    mynet:
  </code></pre>
  
  <p>The container is created correctly and it starts without any problem. Is it possible to create a Mongo collection and populate it with some documents the first time the container starts?</p>
  
  <p>For instance, I'd like to run a few statements like these:</p>
  
  <pre><code>db.strategyitems.insert( { symbol: "chf", eval_period: 15, buy_booster: 8.0, sell_booster: 5.0, buy_lot: 0.2, sell_lot: 0.2 } )
  db.strategyitems.insert( { symbol: "eur", eval_period: 15, buy_booster: 8.0, sell_booster: 5.0, buy_lot: 0.2, sell_lot: 0.2 } )
  db.strategyitems.insert( { symbol: "usd", eval_period: 15, buy_booster: 8.0, sell_booster: 5.0, buy_lot: 0.2, sell_lot: 0.2 } )
  </code></pre>
  
  <p>...</p>