Spring Boot Development Using Docker Container

[1] Setup Java and Maven on host machine

OpenJDK.v.11

Maven.v.3.8.5

[2] Prep Spring Boot project

Download spring boot demo project

archive.org/download/spring-boot/spring-boo..

Unzip to c:\users\user\MySpringBoot\project102\

[3] Build Project

Change directory to project root:

cd c:\users\user\MySpringBoot\project102\

Build project

.\mvnw clean package

Output:

[4] Run container

Create Dockerfile

C:\Users\User\MySpringBoot\project102\Dockerfile

# Use a base image with OpenJDK 17
FROM openjdk:17-slim

# Set the working directory
WORKDIR /app

# Copy the jar file into the container
COPY target/demo-0.0.1-SNAPSHOT.jar demo.jar

# Expose the port the app runs on
EXPOSE 8080

# Command to run the jar
CMD ["java", "-jar", "demo.jar"]

Build image

docker build -t myapp .

Output:

Run container

docker run -p 8080:8080 myapp

Test Container

http://localhost:8080/hello

Web output: