Posts

Showing posts with the label Dockerfile

3 Ways to Dockerize Your Spring Boot Application: Dockerfile, Jib, and Buildpacks

Image
Here’s a guide to generate a Docker image for a Spring Boot application using three different methods . Each method has its use case, depending on your project's needs and complexity. 1. Using a Dockerfile This method gives you full control over the image creation process. Steps: Create a Dockerfile : Create a file named Dockerfile in the root directory of your Spring Boot project with the following content: FROM openjdk: 17 -jdk-slim ARG JAR_FILE=target/app.jar COPY ${JAR_FILE} app.jar ENTRYPOINT [ "java" , "-jar" , "/app.jar" ] Build the JAR file: Package your application into a JAR file: mvn clean package Build the Docker image: Run the following command to build the Docker image: docker build -t spring- boot - app . Run the Docker container: Start the container: docker run -p 8080:8080 spring- boot - app 2. Using Jib (Maven/Gradle Plugin) Jib is a tool from Google that simplifies the process of creating Docker images without needing a D...