DEV Community

Carlos A. Martinez
Carlos A. Martinez

Posted on

2 1

Hello world with Spring Boot and Docker

Image description

This is a small example of how to create a Docker container using Spring boot.

Here we go ...

  1. Create new Spring boot App spring initializr dependencies (spring web)

  2. 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";
    }
}
Enter fullscreen mode Exit fullscreen mode
  1. Build jar file with maven

Image description

  1. 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"]
Enter fullscreen mode Exit fullscreen mode
  1. Generate imagen

>docker build -t image_hello .

  1. Generate container

> docker run --name hello_container -p 9000:8080 image_hello

  1. Test

localhost

Image description

Thank you so much for reading my post

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

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

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay