13

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?

k0pernikus
  • 41,137
  • 49
  • 170
  • 286
migorman
  • 179
  • 1
  • 1
  • 8

7 Answers7

23

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.

Maxim Zubarev
  • 2,127
  • 1
  • 26
  • 44
  • 1
    That's the only valid answer for me as I'm on a cloud server and I surely won't expose my database port or alter any of my containers. Thank you! – Ben Jun 23 '17 at 10:39
  • i have used ecpose in my docker compose file. This only opens port inside the server. So you can you use expose but not ports. This will open it for everybody. Somebody disagree? – KT Works Nov 13 '18 at 17:33
  • Finding the IP address of the MongoDB container was useful, thanks. – spacedev Oct 30 '19 at 09:20
5

The easiest way is to enable forwarding the Mongo Container itself, here's how my docker-compose looks like.

mongo:
  image: mongo
  restart: always
  ports:
    - 27017:27017
Pratyush
  • 1,146
  • 13
  • 13
4

You should do a Robomongo SSH tunnel connection to MongoDB inside docker container. First of all you should install a ssh server inside your docker container.

https://docs.docker.com/engine/examples/running_ssh_service/


After that you should configure your connection in Robomongo. Inside "Connection Settings" there are configuration tabs of your Robomongo Connection.

Go to "SSH" Tab and configure your SSH connection to the docker container. After that go to "Connection" Tab and configure your connection to MongoDB as if it was in localhost scope.

André Bonna
  • 737
  • 7
  • 12
  • Didn't work for me, so i found a workaround which is better aligned with the docker philosophy : made an ssh docker as described, then run it with a `-link _mymongodocker_` parameter (and a port mapping for 22 so i'm sure to find it easily). Then in robomongo instead of localhost i use mymongodocker (as it's linked, it's available from the ssh docker). Works like a charm even if --link is deprecated and should be replaced by a more modern approach, for the time beeing, i'm too lazy :) – Edwin Joassart Aug 19 '16 at 13:55
3

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!

rash.tay
  • 3,877
  • 5
  • 33
  • 60
1

Please note that maybe you won't be able to use ssh because it was just a problem of incompatibility between mongo and robomongo.

'Robomongo v8.5 and lower doesn't support MongoDB 3'. It has nothing to do with docker.

brasskazoo
  • 68,343
  • 22
  • 59
  • 74
migorman
  • 179
  • 1
  • 1
  • 8
0

First log in with ssh Login details

  1. ssh -i yourpemfile.pem username@ipaddress enter image description here

  2. Check running container id for MongoDB

    docker ps -a

  3. then check the mongo container id

docker inspect container_id

enter image description here

  1. Then open robo3t

create new connection and add container id use ssh login details to connect to mongodb

enter image description here enter image description here

Surendra Kumar Ahir
  • 1,395
  • 15
  • 18
-3

In your docker-compose file, you can expose a port to the host.

For example, the following code will expose port 27017 inside the machine to the port 27018 in the host.

app:
  image: node
  volumes:
    - /app
  ports:
    - "27018:27017"

Then, if you have docker-machine installed and your machine is default, you can do in a terminal :

docker-machine ip default

It will give you the ip of your host, for example 192.168.2.3. The address of your database (host) will be 192.168.2.3 and the port 27018.

If your docker machine is not virtual and is your OS, the address of your database will be localhost and the port 27018.

haverchuck
  • 170
  • 1
  • 7
  • 1
    yes haverchuck this is what i did but it seems that for robomongo it needs some more configurations:) – migorman Mar 01 '16 at 11:55