connect robomongo to mongoDB docker container

2020-05-20 08:59发布

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?

5条回答
Ridiculous、
2楼-- · 2020-05-20 09:20

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.

查看更多
倾城 Initia
3楼-- · 2020-05-20 09:23

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
查看更多
看我几分像从前
4楼-- · 2020-05-20 09:27

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.

查看更多
爷的心禁止访问
5楼-- · 2020-05-20 09:29

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.

查看更多
趁早两清
6楼-- · 2020-05-20 09:34

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.

查看更多
登录 后发表回答