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? Answer To access localhost from inside a docker