title: mongod --bind_ip using docker-compose version 2
body: <p>I'm trying to connect two mongodb containers running on docker using <code>docker-compose</code>. One container seed some data to the other using <code>mongoimport</code>.</p>
  
  <p>However, I'm getting the following error when run <code>mongoimport</code></p>
  
  <pre><code>Failed: error connecting to db server: no reachable servers
  </code></pre>
  
  <p>I can actually reach the <code>mongodb</code> container from <code>mongo-seed</code> since I'd appended a <code>ping -c 3 mongodb</code> to the <code>CMD</code> and the container can resolve successfully that hostname.</p>
  
  <p>Below the files I'm using:</p>
  
  <p><strong>docker-compose.yml</strong></p>
  
  <pre><code>version: '2'
  
  services:
    mongodb:
      image: mongo:3.2
      ports:
        - "27017:27017"
  
    mongo-seed:
      build: ./mongo-seed
  </code></pre>
  
  <p><strong>mongo-seed/Dockerfile</strong></p>
  
  <pre><code>FROM mongo:3.2
  
  COPY init.json /init.json
  CMD ping -c 3 mongodb &amp;&amp; mongoimport --host mongodb --db test --collection users \
     --type json --file /init.json --jsonArray
  </code></pre>
  
  <p><strong>mongo-seed/init.json</strong></p>
  
  <pre><code>[
    {
      "name": "Joe Smith",
      "email": "jsmith@gmail.com",
      "age": 40,
      "admin": false
    },
    {
      "name": "Jen Ford",
      "email": "jford@gmail.com",
      "age": 45,
      "admin": true
    }
  ]
  </code></pre>
  
  <p>And this the output of <code>docker-compose up</code>:</p>
  
  <pre><code>mongo-seed_1  | PING mongodb (172.18.0.2): 48 data bytes
  mongo-seed_1  | 56 bytes from 172.18.0.2: icmp_seq=0 ttl=64 time=0.116 ms
  mongo-seed_1  | 56 bytes from 172.18.0.2: icmp_seq=1 ttl=64 time=0.141 ms
  mongo-seed_1  | 56 bytes from 172.18.0.2: icmp_seq=2 ttl=64 time=0.114 ms
  mongo-seed_1  | --- mongodb ping statistics ---
  mongo-seed_1  | 3 packets transmitted, 3 packets received, 0% packet loss
  mongo-seed_1  | round-trip min/avg/max/stddev = 0.114/0.124/0.141/0.000 ms
  mongo-seed_1  | 2016-08-09T20:34:15.728+0000    [........................] smtt.devices 0.0 B/25.5 MB (0.0%)
  mongo-seed_1  | 2016-08-09T20:34:17.992+0000    [........................] smtt.devices 0.0 B/25.5 MB (0.0%)
  mongo-seed_1  | 2016-08-09T20:34:17.992+0000    Failed: error connecting to db server: no reachable servers
  mongo-seed_1  | 2016-08-09T20:34:17.992+0000    imported 0 documents
  mongo_mongo-seed_1 exited with code 1
  </code></pre>
  
  <p>Any idea? What am I missing?</p>