docker pull 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()
docker stop my_mongo
docker start my_mongo
docker container rm my_mongo
docker ps
docker images
docker container ls --all