title: docker container cannot connect to localhost mongodb
body: <p>A. I have a container that includes the following<br>
         1. <code>NodeJS</code> version 8.11.4<br>
         2. <code>Rocketchat</code> meteor app   </p>
  
  <p>B. This is my <code>Dockerfile</code>  </p>
  
  <pre><code>FROM node:8.11.4
  ADD . /app
  RUN npm install -g node-gyp
  RUN set -x \
    &amp;&amp; cd /app/programs/server/ \
    &amp;&amp; npm install \
    &amp;&amp; npm cache clear --force
  WORKDIR /app/
  ENV PORT=3000 \
      ROOT_URL=http://localhost:3000
  EXPOSE 3000
  CMD ["node", "main.js"]
  
  </code></pre>
  
  <p>C. This command is executed well</p>
  
  <pre><code>docker build -t memo:1.0 .
  
  </code></pre>
  
  <p>When I try to run the container, it encounters the following error in containers log</p>
  
  <pre><code>{"log":"MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]\n","stream":"stderr","time":"2019-01-24T21:56:42.222722362Z"}
  
  </code></pre>
  
  <p>So container can not be executed.
  The <code>mongodb</code> is running and I've added 0.0.0.0 to <code>bindIp</code> in the <code>mongod.conf</code> file.</p>
  
  <pre><code># network interfaces
  net:
    port: 27017
    bindIp: 127.0.0.1,0.0.0.0  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
  </code></pre>
  
  <p>My <code>mongodb</code> is installed in host(outside the container)<br>
  The problem was not resolved and my container status is Exited</p>
  
  <p>I put the IP instead of the localhost,but it encounters the following error</p>
  
  <pre><code>{"log":"MongoNetworkError: failed to connect to server [192.168.0.198:27017] on first connect [MongoNetworkError: connect EHOSTUNREACH
  
  </code></pre>