问题
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:
Pull/Restart the docker container mongodb
Enter the bash shell
docker exec -it mongodb bashNow 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:
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