Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connect robomongo to mongoDB docker container

I'm running a NodeJS App with docker-compose. Everything works fine and I can see all my data by connecting to Mongo inside container. But when I connect to RoboMongo I don't see any data.

How can I deal with this problem?

like image 745
kira Avatar asked Mar 01 '16 10:03

kira


People also ask

How can I access a MongoDB container from another container?

If you need to access the MongoDB server from another application running locally, you will need to expose a port using the -p argument. Using this method, you will be able to connect to your MongoDB instance on mongodb://localhost:27017 . You can try it with Compass, MongoDB's GUI to visualize and analyze your data.

How do I access MongoDB containers?

You can connect to MongoDB on localhost:27017 . Then use the following command to open the MongoDB shell. I have used mymongo as an arbitrary container name, though you can replace mymongo with test-mongo or any other container name of your choosing. The show dbs command will display all your existing databases.


2 Answers

There is another way. You can

  1. SSH with Robomongo into your actual virtual server that hosts your docker applications (SSH tab, check "Use SSH tunnel" and complete the other fields accordingly)
  2. Now ssh into the same machine in your terminal.
  3. docker ps should show you your MongoDB container.
  4. docker inspect <mongo container id> will print out complete information about that container. Look for IPAddress in the end, that will give you the local IP of the container.
  5. In the "Connection" tab in Robomongo use that container IP to connect.

Another sidenote: Make sure that you don't expose your mongodb service ports in any way (neither Dockerfile nor docker-compose.yml), cause that will make your database openly accessible from everywhere. Assuming that you don't have set up a username / password for that service you will be scanned and hacked soon.

like image 53
Maxim Zubarev Avatar answered Sep 23 '22 03:09

Maxim Zubarev


I was facing a different problem. I had installed MongoDB locally. So, when the MongoDB on docker was running, it was clashing with the one running on my host. I had installed it using brew.

So, I ran

brew services stop mongodb-community

and then I restarted Robo3t. I saw the databases created in the MongoDB running on the docker.

Voila!

like image 22
shet_tayyy Avatar answered Sep 21 '22 03:09

shet_tayyy