Installing MongoDB with Docker

Author: Al-mamun Sarkar Date: 2020-09-11 09:41:42

In this lesson, I will show you how to install MongoDB on a docker container and how to run a MongoDB query.

 

Running Mongo Docker Container with the latest version:

sudo docker run -d -p 27017:27017 -v :data/data/db mongo

 

Login into docker bash terminal (determined_pasteur is container name):

docker exec -it determined_pasteur bash

MongoDB installed successfully on a docker container. 

 

Connect Mongo shell with a specific Mongod:

mongo mongodb://127.0.0.1:27018
mongo mongodb://127.0.0.1:27017

The first one will connect with MongoDB which port is 27018 and the second one will connect with which port is 27017.