Pollito Dev
November 23, 2024

Pollito's Opinion on Spring Boot Development 9: Deployment

Posted on November 23, 2024  •  4 minutes  • 692 words  • Other languages:  Español

Some context

This is the ninth part of the Spring Boot Development blog series.

In this blog we are going to focus on deploying the microservice. Let’s start!

Why “dockerize” a Spring Boot application

1. Portability across environments

2. Ease of deployment

3. Scalability

4. Isolation

5. Simplified CI/CD pipelines

6. Improved resource utilization

7. Versioning and rollbacks

8. Cloud-Native alignment

9. Simplifies team collaboration

Dockerfile

Dockerfile

# Build Stage
FROM maven:3.9.9-eclipse-temurin-21-alpine AS build
WORKDIR /app
COPY pom.xml .
COPY src ./src
RUN mvn clean package -DskipTests

# Run Stage
FROM eclipse-temurin:21-jre-alpine
WORKDIR /app
COPY --from=build /app/target/*.jar app.jar
CMD ["java", "-jar", "app.jar"]

Stage 1: Build Stage

FROM maven:3.9.9-eclipse-temurin-21-alpine AS build
WORKDIR /app
COPY pom.xml .
COPY src ./src
RUN mvn clean package -DskipTests

Result: The compiled .jar file will be created in the target/ directory.

Stage 2: Run Stage

FROM eclipse-temurin:21-jre-alpine
WORKDIR /app

Working Directory: Again sets the working directory as /app.

COPY --from=build /app/target/*.jar app.jar
CMD ["java", "-jar", "app.jar"]

Deployment

I decided to deploy the app in Render , because:

Nonetheless, there are many options out there, or you can always create your own VPS.

Here’s the tutorial I followed:

Next lecture

Work in progress…

Hey, check me out!

You can find me here