Skip to content

Instantly share code, notes, and snippets.

@agu3rra
Created February 14, 2020 23:05
Show Gist options
  • Save agu3rra/f6347cb45941a0d736dfb13fd49d16fb to your computer and use it in GitHub Desktop.
Save agu3rra/f6347cb45941a0d736dfb13fd49d16fb to your computer and use it in GitHub Desktop.
Docker commands for playing with MongoDB
# Run a container and expose port to host
docker run --name mongo-instance-01 -p 27017:27017 -d mongo:latest
# Access its terminal
docker ps
docker exec -it <container-id> bash
# Run the same mongo DB in the above example with persistence.
docker volume create mongo-volume-01
docker run \
--name mongo-instance-01 \
-p 27017:27017 \
--mount 'type=volume,src=mongo-volume-01,dst=/data/db/' \
-d mongo:latest \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment