title: MongoDB on with Docker "failed to connect to server [mongo:27017] on first connect"
body: <pre><code>version: '3'
  services:
    app:
      container_name: node-mongo
      env_file:
          &quot;./NodeJs/.env&quot;
      restart: always
      image: style-app
      build:
        context: ./NodeJs
        dockerfile: ./Dockerfile
      ports:
        - '8083:6017'
      external_links:
        - mongo
    mongo:
      container_name: mongo
      image: mongo
      ports:
        - '27017:27017'
    frontend:
      build:
        context: ./frontstyle
        dockerfile: ./Dockerfile
      image: &quot;front-style-frontend&quot;
      ports:
        - &quot;3000:3000&quot;
      links:
        - &quot;app:be&quot;
  </code></pre>
  <p>inside <code>.env</code></p>
  <pre><code>MONGOURI=mongodb://mongo:27017/mydb
  </code></pre>
  <p>inside <code>app.js</code></p>
  <pre><code>var mongoDB = process.env.MONGOURI;
  mongoose.connect(mongoDB, { useNewUrlParser: true})
  </code></pre>
  <p>I don't know why this is not connecting correctly if I create image for mongo then I run docker-compose up it says already The container name <code>&quot;/mongo&quot;</code> is already in use by container.</p>
  <p>Please guide</p>