Sometimes you might need multiple instances of mongo or mysql installed. Instead of installing them locally, just user the dockerimage
Having the databases on docker containers gives me flexibility in swaping databases pretty easily.
Before starting, to persist the databases, we need to store the volumes somewhere. I like to make a "databases" folder in my home folder, but you can put them wherever you want. Just make sure to persist them
docker run -d --name mongo3.6 -p 27017:27017 -v ~/databases/mongo3.6:/data/db mongo:3.6
# Docker downloads mongo:3.6
# Docker runs mongo.
docker stop mongo3.6
# Next time you can start the container by doing: docker start mongo3.6
Same thing for mongo3.2 (make sure you are not running the mongo3.6 container
docker run -d --name mongo3.2 -p 27017:27017 -v ~/databases/mongo3.2:/data/db mongo:3.2
# Docker downloads mongo:3.2
# Docker runs mongo.
docker stop mongo3.2
# Next time you can start the container by doing: docker start mongo3.2
If you want multiple instances of mongo running at the same time just make sure to define a different port in your pc.
This same thing could work for databases like MariaDB
docker run -d --name maria -p 3306:3306 -v ~/databases/maria:/var/lib/mysql mariadb:10.3