This is a small example of how to create a Docker container using Spring boot.
Here we go ...
Create new Spring boot App spring initializr dependencies (spring web)
Create new class HelloWorldController.java
@RestController
@RequestMapping("/api/v1/hello-world")
public class HelloWorldController {
@GetMapping()
public String getHelloWorld(){
return "Hello everyone from Spring Boot App";
}
}
- Build jar file with maven
- Create Dockerfile in project root
FROM openjdk:11
ADD target/demo-hello-0.0.1-SNAPSHOT.jar demo-hello.jar
EXPOSE 8090
ENTRYPOINT ["java", "-jar", "demo-hello.jar"]
- Generate imagen
>docker build -t image_hello .
- Generate container
> docker run --name hello_container -p 9000:8080 image_hello
- Test
Thank you so much for reading my post
Top comments (0)