The Wayback Machine - https://web.archive.org/web/20230102210648/https://www.geeksforgeeks.org/how-to-run-mongodb-as-a-docker-container/
Skip to content
Related Articles

Related Articles

How to Run MongoDB as a Docker Container?

Improve Article
Save Article
  • Last Updated : 02 Nov, 2022
Improve Article
Save Article

MongoDB is an open-source document-oriented database designed to store a large scale of data and allows you to work with that data very efficiently. It is categorized under the NoSQL (Not only SQL) database because the storage and retrieval of data in MongoDB are not in the form of tables. 

Running MongoDB as a docker container

Step 1:  Pull the MongoDB container.

docker pull mongo:latest

Pulling-MongoDB-container

Pulling the container

Step 2: Run the container.

docker run -d -p 27017:27017 –name=mongo-example mongo:latest

Running-the-container

Running the MongoDB container

Where -d flag runs the container in detach (background) mode, -p 27017:27017  bound container’s port 27017 to 27017  of host and –name=mongo-example will give name to your container instead of arbitrary name.

Step 3: Verify the state.

docker ps 

Verifying-state

 

As you can see the container is running successfully.

Step 4: Access the MongoDB shell in the running container

docker exec -it mongo-example mongo

Accessing-MongoDB-shell

 

As you can see we can access the interactive shell.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!