Search code examples
javaspring-bootdockerintellij-ideadocker-desktop

How connect to db when running Dockerfile?


I have a spring boot app that connects fine to my PostgreSQL server running locally in Desktop Docker.

Than I wrote a simple Dockerfile to run my app in container. Container starts but can't connect to my db server with error message:

Connection to localhost:5432 refused.

Why and how to fix this?


Solution

  • To access localhost from inside a docker container you can use the IP of your computer. Localhost or 127.0.0.0 donsen't work.