msr-documentation

Docker Run

First create a user deifned bridge network if not already available and connect all your containers to the same network. Once connected to the same user-defined network, containers can communicate with each other using container IP addresses or container names. Refer the docker docs on networking for more details.

docker network list
docker network create msr

The MongoDB Inc community version : docker pull mongodb/mongodb-community-server

Here is the link to docker hub with a detailed installation instructions here

Few points to note

docker run --detach --name mongodb --network msr --publish 27017:27017 --volume C:\home\Projects\msr\data\mongodbinc:/data/db --env MONGODB_INITDB_ROOT_USERNAME=admin --env MONGODB_INITDB_ROOT_PASSWORD=password mongodb/mongodb-community-server:7.0-ubi8

[!WARNING] The path for the volume is OS specific. The above was run from a Windows command Prompt

To manage your MongoDB server or to access, import, and export your data, you can use a second MongoDB container from which you will run the necessary CLI tools. To open up a Mongo Shell session to your MongoDB Atlas server, use mongosh and specify the cluster URL.

docker run -it --name mongosh mongodb/mongodb-community-server:7.0-ubi8 mongosh "mongodb://username:password@clusterURL/database"

[!CAUTION] I have not tried this on my local yet.

The Open Source version : docker pull mongo

Here is the link to the docker hub

docker run --detach --name mongodb --network msr --publish 27017:27017 --volume C:\home\Projects\msr\data\\mongodb:/data/db --env MONGO_INITDB_ROOT_USERNAME=admin --env MONGO_INITDB_ROOT_PASSWORD=password mongo:7.0.5

[!WARNING] The path for the volume is OS specific. The above was run from a Windows command Prompt

The following example starts another MongoDB container instance and runs the mongosh (use mongo with 4.x versions) command line client against the original MongoDB container from the example above, allowing you to execute MongoDB statements against your database instance:

docker run -it --network msr --rm mongo mongosh --host mongodb test

[!CAUTION] I have not tried this on my local yet.

Some usefull docker commands

The docker exec command allows you to run commands inside a Docker container. The following command line will give you a bash shell inside your mongo container:

docker exec -it mongodb bash

The MongoDB Server log is available through Docker’s container log:

docker logs mongodb