0

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!

  • 2
    How are you configuring `spring.datasource.url`? (Consider adding a `SPRING_DATASOURCE_URL` environment variable for a Compose-specific setup.) Also see [Communications link failure , Spring Boot + MySql +Docker + Hibernate](https://stackoverflow.com/questions/58880998/communications-link-failure-spring-boot-mysql-docker-hibernate) which discusses a similar class of problem. – David Maze Apr 10 '23 at 17:36
  • I add spring.datasource.url! but, not working – Bruno Barbosa Apr 16 '23 at 02:02

0 Answers0