Docker container getting connection refused from postgres container in docker-compose

Your port mapping is meaningless inside the docker network. This is only a mapping to the host system. Inside the network, the container is always available on its native port.

 - SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/dbname

Also note that you don’t need to publish the port to access it from inside the network. Doing so for a database can impose security risks. If you can, you should not publish it. That way, it will be only accessible from inside the docker network.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top