I have a working setup of Spring boot application connecting to Postgres DB in docker. The same Spring boot application throws an exception when I move it to another docker container. The Postgres docker was unchanged. What might be wrong ? Why is the same application working outside docker and not connecting to Postgres when put inside docker.
org.postgresql.util.PSQLException: Connection to MYDOMAIN:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
application.properties
spring.datasource.url=jdbc:postgresql://MYDOMAIN:5432/
UPDATE
When I changed MYDOMAIN to the public IP address of the machine hosting Postgres docker, it worked fine. But why is the domain name not getting resolved ?