title: How to import json into mongo using docker-compose?
body: <p>I'm trying to start a docker container with mongodb image and import a default json set.
  I've seen a lot of people recommend --host flag but it doesn't seem to help.</p>
  
  <pre><code>version: '3'
  services:
      db:
          image: mongo:3.4.1
          build: db
          ports:
              - "27017:27017"
  </code></pre>
  
  <p>and dockerfile</p>
  
  <pre><code>FROM mongo
  WORKDIR /usr/src/db
  COPY init.json .
  RUN mongod --bind_ip 127.0.0.1 --fork --logpath /var/log/mongodb.log
  RUN mongorestore --host 127.0.0.1 --db test --collection users /usr/src/db/init.json
  </code></pre>
  
  <p>but I get the usual message </p>
  
  <pre><code>Step 5/5 : RUN mongorestore --host 127.0.0.1 --db test --collection users /usr/src/db/init.json
  ---&gt; Running in f953a6fd5331
  2018-01-17T23:16:54.854+0000    Failed: error connecting to db server: no reachable servers
  ERROR: Service 'db' failed to build: The command '/bin/sh -c mongorestore --host 127.0.0.1 --db test --collection users /usr/src/db/init.json' returned a non-zero code: 1
  </code></pre>
  
  <p>I tried IP addresses 0.0.0.0, 127.0.0.1, the container name "db", with/without starting daemon, runing commands in various orders between docker-compose and dockerfile but nothing. </p>