connecting to Mongodb inside a docker with mongodb compass GUI connecting to Mongodb inside a docker with mongodb compass GUI docker docker

connecting to Mongodb inside a docker with mongodb compass GUI


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.


With docker-compose you just have to expose the port 27017. When You hit "Connect" in the GUI it will auto-detect this connection.

version: "3"services:  mongo-database:    container_name: mongo-database    image: mongo:4    ports:      - 27017:27017


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