Docker with Spring Boot cheat
Sheet.
what is Docker?
How to dockerize a spring boot app?
1. Create a Dockerfile at the root level of your Project and below commands into it.
Dockerfile content :
FROM openjdk:17-jdk-slim: Uses a lightweight Java 17 image.
WORKDIR /app: Sets /app as the working directory inside the container.
COPY target/my-spring-app.jar app.jar: Copies your built app into the container.
ENTRYPOINT: Specifies the command to run your app.
2. Install Docker Desktop on your machine.
3. Build the Docker Image:
docker build -t my-spring-app .
once this command execution is successful, an image will be created which can be viewed in
the Docker Desktop
4. Run the Container:
docker run -p 8080:8080 my-spring-app
This command will run the container and will start your application.
You can also find the containers running in Docker Desktop.