Skip to content
Advertisement

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?

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement