This post walks you through the steps of creating a simple Spring Boot web application with NGINX and MongoDB running inside Docker containers

What you'll need

  • Docker CE

Stack

  • Docker
  • Spring Boot
  • MongoDB
  • NGINX
  • Maven

Project structure

├── app
│   ├── src
│   │   └── main
│   │       ├── java
│   │       │   └── com
│   │       │       └── hellokoding
│   │       │           └── springboot
│   │       │               ├── IndexController.java
│   │       │               └── WebApplication.java
│   │       └── resources
│   │           ├── static
│   │           │   ├── css
│   │           │   │   └── main.css
│   │           │   └── js
│   │           │       └── main.js
│   │           ├── templates
│   │           │   └── index.ftl
│   │           └── application.properties
│   ├── Dockerfile
│   ├── docker-springboot.iml
│   └── pom.xml
├── nginx
│   └── conf.d
│       └── app.conf
└── docker-compose.yaml

Spring Boot Web application

Application dependencies


Controller


FreeMarker View template


Application Configuration


Dockerize

Dockerfile of Spring Boot web application


NGINX config file


Docker Compose


Test

  • Run command docker-compose up
  • Access to http://localhost

Source code

[email protected]:hellokoding/dockercompose-springboot-mongodb-nginx.git

https://github.com/hellokoding/dockercompose-springboot-mongodb-nginx