Dockerizing Spring Boot 3 Application
Tags: docker, springboot
Published: 2023-06-18 04:28:13

watch video

{% embed https://youtu.be/TTGpqKU7UYY %}


step : create spring boot project


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5gdl9nfuyu2retgk2w4r.png)

step : add dependency


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/22n836tpafgjzd2yp8g2.png)


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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5mekur1cttdtm83m5bl0.png)

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

```

step : first run project as maven clean


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/45v5npiq3od92hrx9jyy.png)

step : then run project as maven install


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/whksjfjx7jiy7dwd5g98.png)


step : inside target folder you will see the jar file


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j1lyl6r2gspzzpv2u63g.png)

step : run the jar file

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a5xxk3j6wuy8680e39nb.png)

then go inside target folder

open command prompt inside target folder


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dns1akf0ka51iixra9g3.png)

execute below cmd


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r3glgh8b3usl60jbl6av.png)



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bcsqiwogz575dcwsxe6f.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gvn9euk1snw9wh00nkgs.png)


test app in browser


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l3dp4wpc7clhg8wk7sz0.png)

step : create Dockerfile inside spring boot project


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9mrjcncutv04jpntbgnk.png)



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fqre7itwvarphmam5m3l.png)



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eu2221csh80jgtoq3ljf.png)


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"]
```

step:open cmd prompt inside the project


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3yt7vqccxid5am9kfw5k.png)


run below cmd


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yf1xodzv94jb4s5shr4h.png)


run docker images



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4zp5hu7fuglr2i9o38p.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xmdzmxmwk0zhpamcb9aa.png)


run docker image


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u9x2fn4t5tla7ay6eu8v.png)

test inside browser


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/udgjbpjb56t6aqdnzkd1.png)