Skip to content

Instantly share code, notes, and snippets.

@k0emt
Last active March 21, 2022 02:44
Show Gist options
  • Save k0emt/f80530f34079f8e9afdfddbd0660629e to your computer and use it in GitHub Desktop.
Save k0emt/f80530f34079f8e9afdfddbd0660629e to your computer and use it in GitHub Desktop.
Some helpful docker commands for working with mongoDB

Some helpful mongo container docker commands

Get latest image of mongoDB

docker pull mongo

Spin up a container and work with mongo

Spin up a new container named my_mongo from image mongo Mapping and exposing ports 27017-27019 from the container to the host OS: docker run -d -p 27017-27019:27017-27019 --name my_mongo mongo

Get an interactive shell in the container: docker exec -it my_mongo bash At this point, you will most likely want to run mongosh Exit mongosh with exit or ctrl-d To terminate your mongosh session and shutdown the server:

use admin
db.shutdownServer()

Other helpful docker commands

docker stop my_mongo

docker start my_mongo

docker container rm my_mongo

docker ps

docker images

docker container ls --all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment