2

I'm running a PostgreSQL as a native app(NOT CONTAINER) on my localhost I'm able to connect to it with an SQL client.

While I'm running a spring application - in a container the app starts and fails while trying to connect the database

Caused by: org.postgresql.util.PSQLException: Connection to localhost:5432 refused. 
Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

in my docker image, I have used expose to open the port, but it still won't work

EXPOSE 8080 8443 4000 5432

What can i do to fix it

I run my image with

docker run ec0bdea074a6

Tried also

docker run -p 5432:5432/tcp -p 5432:5432/udp ec0bdea074a6

And it didnt work as well

0

2 Answers 2

2

Changes the url from localhost to

host.docker.internal

Meaning:

  dw.url=jdbc:postgresql://host.docker.internal:5432/DW
Sign up to request clarification or add additional context in comments.

Comments

0

EXPOSE acts as documentation, just like comments in the Dockerfile. You need to use -p flag in the docker run command. See the docs for more details: https://docs.docker.com/engine/reference/builder/#expose

2 Comments

Some tools hook into EXPOSE, though. So it's a bit more than documentation. It's more like a label.
@oartart didnt solve the issue, still failing with the same error docker run -p 5432:5432/tcp -p 5432:5432/udp ec0bdea074a6

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.