title: Docker-compose mongoose
body: <p>I'm new to Docker, and I'm trying the simplest of setups with docker-compose, but don't succeed to connect to Mongodb.  </p>
  
  <p>My docker-compose.local.yaml file: </p>
  
  <pre><code>version: "2"
  services:
    posts-api:
      build:
        dockerfile: Dockerfile.local
        context: ./
      volumes:
        - ".:/app"
      ports:
        - "6820:6820"
      depends_on:
        - mongodb
    mongodb:
      image: mongo:3.5
      ports:
        - "27018:27018"
      command: mongod --port 27018
  </code></pre>
  
  <p>My Docker file: </p>
  
  <pre><code>FROM node:7.8.0
  MAINTAINER Livefeed 'project.livefeed@gmail.com'
  
  RUN mkdir /app
  VOLUME /app
  WORKDIR /app
  
  ADD package.json yarn.lock ./
  RUN eval rm -rf node_modules &amp;&amp; \
  yarn
  
  ADD server.js .
  RUN mkdir config src
  ADD config config/
  ADD src src/
  
  EXPOSE 6820
  EXPOSE 27018
  
  CMD yarn run local
  </code></pre>
  
  <p>In server.js I try to connect with:  </p>
  
  <pre><code>mongoose.connect('mongodb://localhost:27018');
  </code></pre>
  
  <p>I also tried: </p>
  
  <pre><code>mongoose.connect('mongodb://mongodb:27018');
  </code></pre>
  
  <p>To run docker-compose: </p>
  
  <pre><code>docker-compose -f docker-compose.local.yaml up --build 
  </code></pre>
  
  <p>And I receive the error:  </p>
  
  <pre><code>connection error: { MongoError: failed to connect to server [localhost:27018] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27018]
  </code></pre>
  
  <p>What am I missing? </p>