9951 explained code solutions for 126 technologies


mongodbHow to install MongoDB with Docker?


  1. Install Docker on your machine. Refer to the Docker installation guide for instructions.

  2. Pull the MongoDB image from the Docker Hub.

docker pull mongo
  1. Run the MongoDB container.
docker run --name my-mongo -d mongo
  1. Check the container is running.
docker ps

Output example

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
f8f9f9f9f9f9        mongo               "docker-entrypoint.s…"   5 minutes ago       Up 5 minutes        27017/tcp           my-mongo
  1. Connect to the MongoDB instance.
docker exec -it my-mongo mongo

Edit this code on GitHub