I have a Spring Boot 3 + PostgreSQL application, I'm currently using Postgresql with Docker
# Define a imagem base a ser utilizada
FROM openjdk:17-jdk-slim
# Define o diretório de trabalho da aplicação
WORKDIR /app
# Copia os arquivos de build para o container
COPY target/viaAvaliation-0.0.1-SNAPSHOT.jar /app/via.jar
# Expõe a porta utilizada pela aplicação
EXPOSE 8080
# Define o comando a ser executado quando o container iniciar
CMD ["java", "-jar", "via.jar"]
However, if I add the Dockerfile
services:
postgres:
image: 'postgres:14.2'
ports:
- "5432:5432"
restart: always
deploy:
mode: replicated
replicas: 1
environment:
- POSTGRES_USER=root
- POSTGRES_PASSWORD=admin
And I add the Spring application in dockercompose, I have the error of
org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections
I've already added the url to the application.yml by changing localhost to the dockercompose service-name and nothing works!