Docker compose for basic spring boot app

santosh
2 min readFeb 14, 2025

--

Problem Statement

We need to containerise our application meaning we will use docker to build our spring boot application image, which will connect to postgres db running in another container.

Technology used

  • Spring boot
  • java 17
  • maven
  • postgres sql
  • docker

Prerequisite:

  • Docker

Step 1:

We have spring boot project setup who build is passing we can verify with maven

Step 2:

Dockerise spring boot app

We should be able to create image from spring boot source code for that we need Dockerfile as shown below.

Step3

Build image from dockerfile that we will be using finally in docker compose

docker build -t hello-world-docker .

verify with docker command

docker images

Step4:

We will be running postgres sql image in one container and spring boot service image in other container using docker compose

Step5:

Docker-compose to integrate app image and postgres sql image

Step6:

Docker compose

Step7

Verifying with route

https://github.com/san4net/hello-world-docker

Photo by Roman Synkevych on Unsplash

Reference:

--

--

santosh
santosh

No responses yet