Docker: Springboot container can not connect to PostgreSql Container Connection error

前端 未结 3 671
面向向阳花
面向向阳花 2020-12-11 09:33

I am building my first Springboot 2.0 application. I am trying to put my Springboot application into one docker container and my PostgresDB into another container.

3条回答
  •  眼角桃花
    2020-12-11 09:57

    You are pointing your application towards localhost, but this is not shared between containers.

    To access another container you have to refer to its hostname.

    you should use the following datasource url:

    spring.datasource.url=jdbc:postgresql://pgdb:5432/java_learning
    

    See this simple tutorial about connecting to a container from another container with docker compose: https://docs.docker.com/compose/gettingstarted/

提交回复
热议问题