I have a SpringBoot application, that runs perfectly on Tomcat and connects to a Postgres database.
e.g. application.properties
# approval datasource
spring.datasource2.driver-class-name=org.postgresql.Driver
spring.datasource2.jdbc-url=jdbc:postgresql://localhost:5432/approval
spring.datasource2.username=postgres
spring.datasource2.password=
Next I have Dockerised the application:
Dockerfile
FROM openjdk:14
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} nexct-approval-service.jar
EXPOSE 8081
ENTRYPOINT ["java","-jar","/nexct-approval-service.jar"]
I can access a restful service in the application, however it is giving the following error:
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.
Everything is running on localhost
and I plan to deploy this to a linux server where everying runs on the same host too.
Question
Why does docker seem to change the host access? How do I configure this so that it can access the database using docker?