DEV Community

realNameHidden
realNameHidden

Posted on • Edited on

2 1 1 1 1

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

Please leave your appreciation by commenting on this post!

Okay, let's go.

Happy coding ❤️

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay