This is my dockerfile
#download the openjdk image
FROM openjdk:17
# add argument to the docker image
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} api-service.jar
# run the jar file
ENTRYPOINT ["java","-jar","api-service.jar"]
# expose the port
EXPOSE 8080
And this is my docker-compose.yml
version: "3.9"
services:
spring-boot-postgres-crud:
container_name: spring-boot-postgres-crud
build:
context: ./
dockerfile: Dockerfile
ports:
- "8080:8080"
expose:
- "8080"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=1505
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/ems
- SPRING_DATASOURCE_USERNAME=postgres
- SPRING_DATASOURCE_PASSWORD=1505
- SPRING_JPA_HIBERNATE_DDL_AUTO=update
depends_on:
- db
networks:
- backend
db:
image: postgres
container_name: db
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=1505
- POSTGRES_DB=ems
ports:
- "5432:5432"
networks:
backend:
driver: bridge
And this is my applications.properties
spring.application.name=CRUD_SpringBoot_PostgreSQL
spring.datasource.url=jdbc:postgresql://db:5432/ems
spring.datasource.username=postgres
spring.datasource.password=1505
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.diaplect=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.driver-class-name=org.postgresql.Driver
and this is my applycations.yml
server:
port: 80
spring:
application:
name: CRUD_SpringBoot_PostgreSQL
profiles:
# active: dev
active: @spring.profiles.active@
I used maven command “mvn clean package -DskipTests -P dev” and it can build the jar file.
I used maven command “mvn clean package -P dev” and it can not build the jar file and have error.
then I use command “docker-compose up -d spring-boot-postgres-crud” it have error
org.postgresql.util.PSQLException: The connection attempt failed.