Connect Robomongo To MongoDB Docker Container
Answer :
There is another way. You can
- 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)
- Now ssh into the same machine in your terminal.
docker ps
should show you your MongoDB container.docker inspect <mongo container id>
will print out complete information about that container. Look forIPAddress
in the end, that will give you the local IP of the container.- 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.
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
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.
Comments
Post a Comment