9951 explained code solutions for 126 technologies


mongodbHow to create a database with MongoDB on Docker?


Creating a MongoDB database with Docker is a simple process.

  1. Pull the MongoDB image from Docker Hub:
docker pull mongo
  1. Run the MongoDB container:
docker run -d -p 27017:27017 --name mongodb mongo
  1. Connect to the MongoDB container:
docker exec -it mongodb bash
  1. Create a database:
mongo
use my_database

The above steps will create a MongoDB database called my_database on Docker.

Helpful links

Edit this code on GitHub