title: Docker: Unable to connect to database
body: <p>Been stuck on this for a whole day I can't seem to figure this out. I am new to Docker, and I cannot seem to figure out why I cannot connect to my Mongo database using Docker but I'm able to outside of it. Please guide me.</p>
  <p>error</p>
  <pre><code>MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
      at NativeConnection.Connection.openUri (/home/server/node_modules/mongoose/lib/connection.js:832:32)
      at /home/server/node_modules/mongoose/lib/index.js:345:10
      at /home/server/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:5
      at new Promise (&lt;anonymous&gt;)
      at promiseOrCallback (/home/server/node_modules/mongoose/lib/helpers/promiseOrCallback.js:30:10)
      at Mongoose._promiseOrCallback (/home/server/node_modules/mongoose/lib/index.js:1135:10)
      at Mongoose.connect (/home/server/node_modules/mongoose/lib/index.js:344:20)
      at Object.&lt;anonymous&gt; (/home/server/server.js:17:10)
      at Module._compile (internal/modules/cjs/loader.js:1118:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1138:10)
      at Module.load (internal/modules/cjs/loader.js:982:32)
      at Function.Module._load (internal/modules/cjs/loader.js:875:14)
      at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
      at internal/main/run_main_module.js:17:47 {
    reason: TopologyDescription {
      type: 'Unknown',
      setName: null,
      maxSetVersion: null,
      maxElectionId: null,
      servers: Map(1) { 'localhost:27017' =&gt; [ServerDescription] },
      stale: false,
      compatible: true,
      compatibilityError: null,
      logicalSessionTimeoutMinutes: null,
      heartbeatFrequencyMS: 10000,
      localThresholdMS: 15,
      commonWireVersion: null
    }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/LZVby.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LZVby.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/tVvgk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tVvgk.png" alt="enter image description here" /></a><a href="https://i.stack.imgur.com/jckQm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jckQm.png" alt="enter image description here" /></a></p>