title: Can't connect to mongo docker image with mongoose
body: <p>I'm trying to run a simple docker setup with node and mongo:</p>
  
  <p><strong>Dockerfile:</strong></p>
  
  <pre><code> FROM node:8.9.4-alpine
   RUN mkdir /app
   WORKDIR /app
   COPY package.json /app/
   COPY package-lock.json /app/
   RUN npm install
   ADD . /app/
  </code></pre>
  
  <p><strong>docker-compose.yml:</strong></p>
  
  <pre><code>version: '3'
  
  services:
    db:
      image: 'mongo'
      ports:
        - "27017:27017"
    api:
      build: .
      restart: always
      command: sh -c "npm install &amp;&amp; npm run start"
      volumes:
        - .:/app
      ports:
        - "3000:3000"
      environment:
        PORT: 3000
      depends_on:
        - db
  </code></pre>
  
  <p>Now in my <strong>app.js</strong> I'm connecting to mongo like that:</p>
  
  <pre><code>mongoose.connect('mongodb://localhost:27017')
    .catch(err =&gt; {
      console.log(err)
    })
  </code></pre>
  
  <p><strong>However I'm getting a</strong> <code>failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]</code></p>
  
  <p>The mongo container seems to boot up and run fine giving me <code>waiting for connections on port 27017</code>.</p>
  
  <p>What's wrong with my setup? I also tried swapping out <code>localhost</code> for <code>mongo</code> when connecting, but it had no effect either.</p>