Title: Connection Refused Error When Running Spring Boot Application with Docker Compose
Description:
I'm encountering an issue when trying to run a Spring Boot application along with a PostgreSQL container using Docker Compose. The Spring Boot application is unable to connect to the PostgreSQL container, and I'm consistently getting the following error:
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 am using two separate Docker Compose files, one for the Spring Boot application and another for the PostgreSQL container.
In the Spring Boot application properties, I'm using the correct PostgreSQL container name in the datasource URL:
spring.datasource.driver-class-name= org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://my-container:5432/mydb
spring.datasource.username=admin
spring.datasource.password=admin
Despite these configurations, the connection is refused, and the Spring Boot application fails to start.
Any ideas PLEASE
Comment From: mhalbritter
I don't think that services defined in two different compose files share the same network. Why did you use two compose files instead of one?
It feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.