This repository contains a Spring Boot example project for a MongoDB running on Docker.
This is a kind of quick and dirty application. Just meant to do some CRUD operations with MongoDB.
Definitely not the definitive resource on MongoDB, but it is a working example.
Java - The Main Programming Language and Framework.
Spring Boot - Software Platform for creating and delivering Android Applications.
Thymeleaf - A Java template engine.
MongoDB - A cross-platform document-oriented database program.
Maven - Build tool & Dependency Management.
Intellij Idea - Java IDE.
- Download Docker Desktop for your OS/platform.
- Pull the Mongo image with the command :
$ docker pull mongo
- Run the mongo image using the command :
$ docker run -p 27017:27017 -d mongo
- As mentioned in MongoDB Documentation on Docker Hub:
The option -p sets host:remote ports. Moreover, we specified 27017 for both parts cause in the host part , spring boot will look for the default mongoDB port which is 27017, whereas in the remote port [in the docker image] mongo image is set to port 27017 by default.
- Optional : When the Docker container gets closed, your data will not be persisted.
- To be able to persist data in your host file system , use a command like :
$ docker run --name spring_mongodb -p 27017:27017 -v "D:\Projects\Intellij IDEA\spring\Ex#SpringBoot+MongoDB+Docker\docker_data\mongo:/data/db" -d mongo
- The option -v tells docker to map data from the machine/host specified directory to the container's directory of "\data\db".