MongoDB is one of the most popular NoSQL databases in the world, offering flexibility, performance, and high scalability. MongoDB can store and manage both structured and unstructured data, such as documents, graphics, media, and more. MongoDB also supports advanced features, such as indexation, aggregation, replication, sharding, and transactions.
Docker is a software platform that allows you to create, run, and distribute applications using containers. A container is a unit of software isolated from the surrounding environment, which contains everything an application needs to function, such as code, libraries, dependencies, and configurations. With Docker, you can ensure that your applications can run smoothly anywhere, without worrying about compatibility or dependencies.
Installing MongoDB with Docker is an easy and fast way to create a MongoDB database on your computer. You don’t need to manually download or install MongoDB, as Docker will handle all the processes for you. You can also take advantage of Docker features such as volume, networking, and composition to better manage your MongoDB database.

In this article, Bardimin will explain step by step how to install MongoDB with Docker on Windows. I will also provide some tips and tricks to optimize the use of MongoDB with Docker.
Requirement
Before you install MongoDB with Docker, you need to meet the following requirements:
- You must have Docker installed on your computer. If you don’t have Docker yet, you can download and install it from the official Docker website.
- You must have a stable internet connection to download MongoDB images from Docker Hub.
- You must have enough disk space to store MongoDB images and data.
Install MongoDB with Docker on Windows
To install MongoDB with Docker on Windows, follow these steps:
- Open PowerShell or Command Prompt as an administrator.
- Run the following command to create a new directory on drive C: that will be used as a volume to store MongoDB data:
mkdir C:\data\db
- Run the following command to run a MongoDB container named mongo using a mongo image from Docker Hub:
docker run --name mongo -v C:\data\db:/data/db -d mongo
This command will do:
- –name mongo assigns the mongo name to the container.
- -v C:\data\db:/data/db links the C:\data\db directory on the host to the /data/db directory on the container as a volume. This volume will be used by MongoDB to store data.
- -d runs the container in the background (detached mode).
- Mongo specifies the image used to create the container.
- Wait, a few moments for the container to finish creating and running. You can check the status of the container by running the following command:
docker ps
This command will display a list of containers currently running on your machine. You should see an output like this:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5f0b9c8a9f0a mongo "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 27017/tcp mongo
This output shows that the mongo container is running with a mongo image and port 27017 (MongoDB’s default port).
- Congratulations, you have successfully installed MongoDB with Docker on Windows! You can now connect to your MongoDB database using tools you love, such as MongoDB Shell, MongoDB Compass, or MongoDB drivers for your favorite programming language.