Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

[Spring Boot + MongoDB + Docker] Example

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.

Spring MongoDB Docker

Built With

    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.

Steps:

  1. Download Docker Desktop for your OS/platform.
  2. Pull the Mongo image with the command :
$ docker pull mongo
  1. 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.
  1. 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".

Authors

Muhammad Ali - find me on : Twitter, LinkedIn.

About

This repository contains a Spring Boot example project for a MongoDB running on Docker.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages