top of page

How To Dockerize Spring Boot Application

  • Writer: Anand Nerurkar
    Anand Nerurkar
  • Jul 14, 2022
  • 1 min read

How To Dockerize Sample Spring Boot Application-Microservices


Prerequisite

· JDK 11

· DockerHub account and repository

· Docker installed and running

· User must be login to Docker Desktop

· sample microservice – department-service


1. Create a Docker file for the application as below and save it as Dockerfile

--------------------Dockerfile--------------------------------------------

FROM openjdk:11

ARG JAR_FILE=target/*.jar

COPY ${JAR_FILE} department-service.jar

ENTRYPOINT ["java","-jar","/department-service.jar"]

EXPOSE 9001


2. Edit pom.xml file and make entry for spotify docker plugin to build image and push


<plugin>

<groupId>com.spotify</groupId>

<artifactId>dockerfile-maven-plugin</artifactId>

<version>1.4.13</version>

<executions>

<execution>

<id>default</id>

<goals>

<goal>build</goal>

<goal>push</goal>

</goals>

</execution>

</executions>

<configuration>

<repository>anandn76/${project.name}</repository>

<tag>${project.version}</tag>

<useMavenSettingsForAuth>true</useMavenSettingsForAuth>

</configuration>

<dependencies>

<!-- To make this work on JDK 9+ -->

<dependency>

<groupId>javax.activation</groupId>

<artifactId>javax.activation-api</artifactId>

<version>1.2.0</version>

</dependency>

</dependencies>

</plugin>




Yellow block represent docker goals such as build and push


Green part represent your docker hub repository


For below block we need to make below entry in settings.xml file

<useMavenSettingsForAuth>true</useMavenSettingsForAuth>


3. Select your project->maven-> maven build and configure target as below


Click Run. It will build project, build image and push it to your docker hub repository as below.













 
 
 

Recent Posts

See All
Best Chunking Practices

1. Chunk by Semantic Boundaries (NOT fixed size only) Split by sections, headings, paragraphs , or logical units. Avoid cutting a sentence or concept in half. Works best with docs, tech specs, policie

 
 
 
Future State Architecture

USE CASE: LARGE RETAIL BANK – DIGITAL CHANNEL MODERNIZATION 🔹 Business Context A large retail bank wants to “modernize” its digital channels (internet banking + mobile apps). Constraints: Heavy regul

 
 
 

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
  • Facebook
  • Twitter
  • LinkedIn

©2024 by AeeroTech. Proudly created with Wix.com

bottom of page