Spring Boot with Docker Container

Docker is a new revolution for Linux container and it is a powerful tool for MicroService development.
The tutorial will guild you how to build a Spring Boot application and deploy it with Docker container.

I. Technology with Spring Boot Docker tutorial

Java – 8
Maven 3.3.9
Editor: Spring Tool Suite – Version 3.7.3.RELEASE
Docker Container

II. Overview Spring Boot with Docker
1. Structure of Project

springboot docker

2. Step to do

– Create Spring Boot Project
– Configure docker-maven-plugin
– Create a Simple Web Controller
– Build Spring Boot with Docker
– Run Docker container
– Result.

III. Practices
1. Create Spring Boot project

– Open Spring Too Suite, File->New->Spring Starter Project, input project info:

spring boot docker input info

Press Next button, add Spring MVC Web dependency:
spring boot docker add spring mvc web dependencies

Press Finish, Spring Boot Project is created. Open pom.xml file for details:

2. Configure Docker-Maven-Plugin

– Review project info in pom.xml file for info to build Dockerfile

– Build Dockerfile

Place it at /src/main folder of Project

– Add properties in pom.xml

– Add Docker Maven Plugin

3. Create a Simple Web Controller

4. Build Spring Boot project with Docker

Set goals for Maven build:
package docker:build

Log when building Spring Boot with Docker

– Check Docker images:
spring boot docker images

5. Run docker container

Run docker commandline

spring boot docker run docker images

6. Result

spring boot docker result

Log from container:
spring boot docker logs

IV. Source code

Spring Boot with Docker


Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*