connecting to Mongodb inside a docker with mongodb compass GUI

五迷三道 提交于 2020-05-25 18:59:13

问题


I have a mongodb database running on the default port 27017 in a docker container.

Is there a way to connect to the database with the mongodb compass GUI running natively on my ubuntu OS?


回答1:


docker run -p 27018:27017 and then connect from Compass on your host with port 27018. I don't see a reason to expose all ports.




回答2:


Yes we can run

Steps:

  1. Pull/Restart the docker container mongodb

  2. Enter the bash shell

    docker exec -it mongodb bash
    
  3. Now open the mongodb compass community and with same default connection just click connect and the docker container's mongodb will be connected to compass community.

My terminal running docker:
My terminal running docker

Mongodb Compass:
Mongodb Compass




回答3:


Run your mongo container with 'publish-all-ports' option (docker run -P). Then you should be able to inspect the port exposed to the host via docker ps -a and connect to it from Compass (just use your Hostname: localhost and Port: <exposed port>).



来源:https://stackoverflow.com/questions/49493688/connecting-to-mongodb-inside-a-docker-with-mongodb-compass-gui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!