connect robomongo to mongoDB docker container

后端 未结 7 1650
耶瑟儿~
耶瑟儿~ 2021-02-02 17:11

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 RoboMo

相关标签:
7条回答
  • 2021-02-02 17:21

    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.

    0 讨论(0)
  • 2021-02-02 17:28

    First log in with ssh Login details

    1. ssh -i yourpemfile.pem username@ipaddress

    2. Check running container id for MongoDB

      docker ps -a

    3. then check the mongo container id

    docker inspect container_id

    1. Then open robo3t

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

    0 讨论(0)
  • 2021-02-02 17:32

    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!

    0 讨论(0)
  • 2021-02-02 17:38

    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.

    0 讨论(0)
  • 2021-02-02 17:41

    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
    
    0 讨论(0)
  • 2021-02-02 17:44

    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.

    0 讨论(0)
提交回复
热议问题