I am trying to dockerize my spring boot application with postgresql. And i managed to do that. But there is a problem. Since i configure my datasource url in application.properties for dockerizing, everytime when i try to mvn clean install
, it fails. Because the application cannot access to given url on build stage.
Here is the mentioned part of application.properties for better understanding :
spring.datasource.url=jdbc:postgresql://e-bank-db:5432/e-bank
Also in my Dockerfile when the images created for the first time (i mean when i docker-compose build
from zero) , i must skip the test when packaging maven. Otherwise, it is failing too.
Here is my Dockerfile :
FROM openjdk:17-slim AS build
COPY pom.xml mvnw ./
COPY .mvn .mvn
RUN
./mvnw dependency:resolve
COPY src src
RUN ./mvnw package
-DskipTests=true
FROM openjdk:17-slim
WORKDIR e-bank
COPY –from=build target/*.jar e-bank.jar
ENTRYPOINT [“java”, “-jar”, “e-bank.jar”]
And here is my docker-compose.yaml :
version: '3.8' services: e-bank-db: container_name: e-bank-db image: postgres restart: always environment: - POSTGRES_USER=username - POSTGRES_PASSWORD=password - POSTGRES_DB=e-bank ports: - '5432:5432' volumes: - e-bank_db:/var/lib/e-bank-postgresql/data e-bank-app: container_name: e-bank-app image: e-bank build: . ports: - '8080:8080' depends_on: - e-bank-db volumes: e-bank_db: driver: local
I am new to docker. And i would appreciate if someone explains this confusing story. Thank you.