paint-brush
Dockerizing a Spring Boot 3 Applicationby@realnamehidden
288 reads

Dockerizing a Spring Boot 3 Application

by N JJuly 5th, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

In this article, we will learn how to dockerize a spring boot 3 application. If this is something you’re unfamiliar with, no worries, we’ll go step-by-step and build the application from scratch. Let’s dive straight into the steps and code.

People Mentioned

Mention Thumbnail
featured image - Dockerizing a Spring Boot 3 Application
N J HackerNoon profile picture

In this article, we will learn how to dockerize a spring boot 3 application. If this is something you’re unfamiliar with, no worries, we’ll go step-by-step and build the application from scratch.


You can find a youtube video below with my step-by-step process.


Let’s dive straight into the steps and code

create project



add web dependency


create controller pkg and class HelloController


HelloController



package com.example.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
 
 @GetMapping("/hello")
 public String sayHello() {
  return "Hello World";
 }
}


run the application check whether working or not


stop application

run application as maven clean



run application as mvn install

refresh project

and inside target you will see the jar file



go to exact location of jar file on file system and open command prompt

and try to run the jar file


stop the application

create Dockerfile



Dockerfile



FROM eclipse-temurin:17-jdk-alpine
VOLUME /tmp
ADD target/SpringBoot3Docker-0.0.1-SNAPSHOT.jar SpringBoot3Docker-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java","-jar","/SpringBoot3Docker-0.0.1-SNAPSHOT.jar"]


go to exact location of Dockerfile on file system

open command prompt and run below command to create image


>docker build -t springbootdocker:latest .


check whether docker image created or not

>docker images




run the docker image


>docker run -p 3033:8080 springbootdocker





The lead image for this article was generated by HackerNoon's AI Image Generator via the prompt "spring boot".