DEV Community

realNameHidden
realNameHidden

Posted on • Edited on

Dockerizing Spring Boot 3 Application

watch video

step : create spring boot project

Image description

step : add dependency

Image description

step : create controller Package
and inside that package create HelloController class

Image description

HelloController.java

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";
    }
}

Enter fullscreen mode Exit fullscreen mode

step : first run project as maven clean

Image description

step : then run project as maven install

Image description

step : inside target folder you will see the jar file

Image description

step : run the jar file

for running the jar
fo to the file location of the project

Image description

then go inside target folder

open command prompt inside target folder

Image description

execute below cmd

Image description

Image description

Image description

test app in browser

Image description

step : create Dockerfile inside spring boot project

Image description

Image description

Image description

paste below inside Dockerfile

FROM eclipse-temurin:17-jdk-alpine
VOLUME /tmp
ADD target/SpringBootDocker-0.0.1-SNAPSHOT.jar SpringBootDocker-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java","-jar","/SpringBootDocker-0.0.1-SNAPSHOT.jar"]
Enter fullscreen mode Exit fullscreen mode

step:open cmd prompt inside the project

Image description

run below cmd

Image description

run docker images

Image description

Image description

run docker image

Image description

test inside browser

Image description

Top comments (0)