1

I have Java SpringBoot Web-application working on host machine. Application connects to PostgreSQL database. All works well. OS - Ubuntu 18.

Now i need to move application in Docker container, except for PostgreSQL which will remain on host machine.

I installed Docker, rise up container, but my app inside docker cannot connect to PostgreSQL database with default settings (localhost).

Here is my application.properties file:

spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/webdemodb
spring.datasource.username=postgres
spring.datasource.password=123
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL95Dialect
spring.jpa.generate-ddl=true

Here is my Dockerfile:

FROM java:8
WORKDIR /
ADD target/webaccount-1.0-SNAPSHOT.jar app.jar
EXPOSE 8080
RUN fc-cache -f -v
ENTRYPOINT ["java","-jar","/app.jar"]

I read about Docker's networking but didn't find solution. What i need to setup?

4

1 Answer 1

1

For simple usage i've just applied the next option when running container:

--network="host"

Full command:

docker run -d -p 9000:8080 --network="host" --name webaccount webaccount:1.0
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.