Java Full Stack & Real Time Microserives Project @ 8 AM IST - Reach out in email for updates javaexpresschannel@gmail.com

Thursday, May 2, 2024

How to run MongoDB as a Docker Container ?

 To run MongoDB as a Docker container, you can use the official MongoDB Docker image. Here are the steps:



1. Pull the MongoDB Docker image from Docker Hub:

docker pull mongo

2. Run the MongoDB Docker container:

docker run -d -p 27017:27017 --name mongodb mongo

In the above command:

- `-d` option is for running the container in the background (detached mode).

- `-p 27017:27017` option is for mapping the port 27017 of the container to the port 27017 of the host.

- `--name mongodb` option is for naming the container as "mongodb".

- `mongo` is the name of the image.

Now, MongoDB is running in a Docker container and is accessible at `localhost:27017`.

0 comments:

Post a Comment