Spring Boot Application Deploy on Docker

Sachith Ariyathilaka
2 min readSep 27, 2021

Step 01: Install Docker

You have to install docker and related dependencies on your machine. You can find easy guide on following link.

Step 02: Setup POM Dependency

You have to rename jar build with common name. Following are example for this. Make sure you have to add following code line after the </plugins> tag.

<finalName>docker-spring-boot</finalName>

Step 03: Build the Project

Then you have to mvn clean install -DskipTests to generate the jar file on target directory.

Step 04: Add Docker File

Then you have to create docker file on project root directory. Followings are the body of the file.

// JDK version
FROM openjdk:8
// Jar path
ADD target/docker-spring-boot.jar docker-spring-boot.jar
// Port
EXPOSE 8085
ENTRYPOINT ["java", "-jar", "docker-spring-boot.jar"]

Step 05: Run Docker Command

Open the terminal run following command for run docker file.

docker build -t docker-spring-boot .

Step 05: Verify the Image

Now you can verify docker image crated from the docker file using following command.

docker images

Also output need to be display as followings

Step 07: Run the Application

Now you can easily run the spring boot application using following command.

docker run -p 8085:8085 docker-spring-boot

Now your spring boot application run on docker and it can be access through 8085 port.

--

--