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?

jlemon
  • 95
  • 1
  • 9

1 Answers1

1

Artemiy, thanks! 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
jlemon
  • 95
  • 1
  • 9