Docker Community Forums

Share and learn in the Docker community.

Unable to access MongoDB within a container within a Docker Machine instance. Unsure if it what I am trying to do is possible


(Babakmomen) #1

I am running Windows 7 on my desktop at work and I am signed in to a regular user account on the VPN. To develop software, we are to normally open a Dev VM and work from in there however recently I’ve been assigned a task to research Docker and Mongo DB. I have very limited access to what I can install on the main machine.

Here lies my problem:

Is it possible for me to connect to a MongoDB instance inside a container inside the docker machine from Windows and make changes? I would ideally like to use a GUI tool such as Mongo Management Studio to make changes to a Mongo database within a container.

By inspecting the Mongo container, it has the ports listed as: 0.0.0.0:32768 -> 27017/tcp
and docker-machine ip (vm name) returns 192.168.99.111.

I have commented out the 127.0.0.1 binding host ip within the mongod.conf file also.

From what I have researched so far, most users resolve their problem by connecting to their docker-machine IP with the port they’ve set with -p or been given with -P. Unfortunately for me, trying to connect with 192.168.99.111:32768 does not work.

I am pretty stumped and quite new to this environment. I am able to get inside the container with bash and manipulate the database there however I’m wondering if I can do this within Windows. Hopefully i’ve explained this properly, I would have used images but new users cannot upload them.

Thank you if anyone can help.


(Marko Bonaci) #2

You can try the following, when you run the container, use -p 32738:27017 without any IP addresses.
Then try to use 192.168.99.111:32768 to access Mongo on the host machine (if that’s still your docker-machine ip at that time).


(Babakmomen) #3

I had tried that and it still caused the same issue.
Thankfully I found a solution but I’m unsure as to why it works.

I tried to ping 192.168.99.11 from my Windows CMD and there was no response from the Docker-machine even though that was the IP it listed when I did “docker-machine ip default” (default being the name of the vm).

By doing “ifconfig” within the Boot2Docker VM (but not inside the container), I was able to locate another IP listed under eth0. This IP looks something like 134.36.xxx.xxx to me and is pingable. With the Mongo container running I can now access the database from within Mongo Management Studio by connecting to 134.36.xxx.xxx:32768 and manipulate the data from there.

I find it strange that using the VM IP does not work since that is where the container is port forwarding to?


(Jeff Anderson) #4

You mentioned that you connect to a VPN from your Windows host. Is it possible that your VPN configuration forces all traffic through the VPN? You may need to manually add a route to your routing table to make sure that traffic to your 192.168.99.0/24 network doesn’t get routed through the VPN.