Can't connect to mongodb in the docker container
<p>I've build a docker container running a mongodb-instance, that should be exposed to the host.
However, when i want to connect from the host into the mongodb-container, the connection will be denied.</p>

<p><strong>This is my Dockerfile:</strong></p>

<pre><code>FROM mongo:latest

RUN  mkdir -p /var/lib/mongodb &amp;&amp; \
     touch /var/lib/mongodb/.keep &amp;&amp; \
     chown -R mongodb:mongodb /var/lib/mongodb

ADD mongodb.conf /etc/mongodb.conf

VOLUME [ "/var/lib/mongodb" ]

EXPOSE 27017

USER mongodb
WORKDIR /var/lib/mongodb

ENTRYPOINT ["/usr/bin/mongod", "--config", "/etc/mongodb.conf"]
CMD ["--quiet"]
</code></pre>

<p><strong>/etc/mongodb.conf:</strong></p>

<p>And this is the config-file for MongoDB, where i bind the IP 0.0.0.0 explicitly as found <a href="https://stackoverflow.com/questions/17588876/mongodb-conf-bind-ip-127-0-0-1-does-not-work-but-0-0-0-0-works">here on SO</a>, that 127.0.0.1 could be the root cause of my issue (but it isn't)</p>

<pre><code>systemLog:
  destination: file
  path: /var/log/mongodb/mongo.log
  logAppend: true
storage:
  dbPath: /var/lib/mongodb
net:
  bindIp: 0.0.0.0
</code></pre>

<p>The docker container is running, but a connection from the host is not possible:</p>

<pre><code>host$ docker run -p 27017:27017 -d --name mongodb-test mongodb-image
host$ docker ps
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                      NAMES
6ec958034a6f        mongodb-image       "/usr/bin/mongod --co"   4 seconds ago       Up 3 seconds        0.0.0.0:27017-&gt;27017/tcp   mongodb-test
</code></pre>

<p>Find the IP-Address:</p>

<pre><code>host$ docker inspect 6ec958034a6f |grep IPA
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.2",
                    "IPAMConfig": null,
                    "IPAddress": "172.17.0.2",
</code></pre>

<p>Try to connect:</p>

<pre><code>host$ mongo 172.17.0.2:27017
MongoDB shell version v3.4.0
connecting to: mongodb://172.17.0.2:27017
2016-12-16T15:53:40.318+0100 W NETWORK  [main] Failed to connect to 172.17.0.2:27017 after 5000 milliseconds, giving up.
2016-12-16T15:53:40.318+0100 E QUERY    [main] Error: couldn't connect to server 172.17.0.2:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:234:13
@(connect):1:6
exception: connect failed
</code></pre>

<p>When i ssh into the container, i can connect to mongo and list the test database successfully.</p>