It will download from docker registry and start when needed. postgres_db – PostgreSQL DB which runs on port 5432Įxplanation about the configurations I have used in this docker-compose file,īuild – Here we should introduce the image name to build under that service, Here we have our Dockerfile which developed for the API in the same level with docker-compose.yml so using “.” it will capture that docker file and build the handle the api_service when executing this file.Īdditionally we have introduced postgres:11.4 as the docker image for postgreSQL DB.api_service – Spring Boot REST API which runs on port 8080.So add the following content into the docker-compose.yml file, version: "3.7"
I’ll start with using links to build communication between both. You can use one from the following two methods to build this docker-compose setup. There are two ways of building communication between spring boot application and the PostgreSQL database. Spring-boot-project-with-docker-compose-file Using links to Build Communication Between Services. So let’s create the docker-compose.yml file which allows us to combine Spring Boot application and PostgreSQL database in this setup.įirst, go to the project root and create a file named docker-compose.yml Now our application has the instruction to building the Docker image. Docker Compose File With Spring Boot and PostgreSQL Let’s go forward with pointing docker file way, since giving docker image part will cover with postgreSQL image in this same setup. Giving created docker image to the docker-compose setup.Pointing Dockerfile into the docker-compose setup.Now you have two ways of building docker compose setup. FROM openjdk:8-jdk-alpineĪDD build/libs/spring-boot-postgresql-base-project-0.0.1-SNAPSHOT.jar app.jar Then copy the following content into that file. Ok Let’s start the docker image creation,įirst, create a file naming as Dockerfile in your project root folder.
If you don’t have a good understanding of how to use docker with a spring boot application, you can refer our article on How to Dockerize Spring Boot Application. Then you can use both images with docker-compose.
Hence first you need to have docker image for your spring boot application. You can just go and select the version you need from there.īut your project is still not pushed or published as a docker image. PostgreSQL is already available as a docker image from docker hub. Those are the Spring Boot application and PostgreSQL database. In this tutorial, our docker-compose setup using two main services or components. Setup Docker Image For Spring Boot Application