Menu
May 24, 2016 - You're looking at the IP address inside the container which is 172.17.0.2 and only exists 'inside' the docker containers (and between them).
Article ID: KB000579
Issue
After creating a MongoDB instance running in a container via a command similar to the following
you are unable to access the MongoDB instance from another application running in another container. You also can't access it using the MongoDB command line client.
![Docker for mac os Docker for mac os](/uploads/1/2/5/8/125859761/828707487.jpg)
What's the issue, and how can I resolve it so I can access the instance, without publishing the mongodb port?
Prerequisites
Before performing these steps, please read the documentation accompanying the image on Docker Hub.There is some guidance there on configuring, starting, and accessing MongoDB running in a container. If that advice isn't applicable, please continue reading this article.
Resolution
The documentation for the MongoDB instance references container linking, which is a deprecated mechanism forinter-container communication. You may also want to avoid publishing the instance's mongodb port (27017) toreduce the attack surface for the database or to prevent applications outside the node from accessing thedatabase instance.
If you can't reconfigure the MongoDB container to publish the port or the documented access methods don'tmeet your requirements, one of the main issues preventing the
docker run
command mentioned above is thatthere are mutliple network interfaces used in the container, and the default behavior of the container OSis only listening on the loopback interface. This can be corrected by a small change to the docker run
command used to start the container:This starts the container's
mongod
service, requesting it to bind to all network interfaces, not just the internalloopback interface.What's Next
For a more detailed discussion of this issue and the recommended workaround,see this Docker Forums article.