Skip to content

Instantly share code, notes, and snippets.

@aelbore
Last active March 16, 2020 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aelbore/2d70b8622408d5e9af5e7a03a835d5b2 to your computer and use it in GitHub Desktop.
Save aelbore/2d70b8622408d5e9af5e7a03a835d5b2 to your computer and use it in GitHub Desktop.
Getting Started with Mongodb Docker

Requirements

Getting Started

  1. Launch Terminal or Command Prompt
  2. Type docker --version to check the version of docker
  3. Pull docker image type docker pull mongo (this will get the latest version of mongodb)
  4. Type docker images to check list of images downloaded
  5. To run the mongodb type docker run -p <host-port>:<expose-port> --name mongodb <image-to-use>
  6. To exit Ctrl+C
  7. To run in the background (detached mode) type docker run -d -p 27017-27019:27017-27019 --name mongodb <image-to-use>
  8. To list all running containers type docker ps -a
  9. To stop running container type docker stop <name-of-container/container-id>
  10. To remove container type docker rm <name-of-container/container-id>
  11. Run again mongodb as detached mode see #7 step
  12. Use RoboMongo as yung GUI to query data
  13. Go inside bash docker docker exec -it <name-of-your-container> bash

Mounting the volume

  1. docker run --name mongo-test -d -v /mongodb/data/db:/data/db -p 27017:27017 mongo:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment