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

前端 未结 3 667
面向向阳花
面向向阳花 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

    Try with :

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

    The postgres database is not running on localhost, it's running in the other container which has an other IP (yet unknown).

    Thanksfully, docker-compose automatically create a network shared among all the containers in the docker-compose.yml (unless explicitly said to do not), as a result you can magically use the service name as an hostname.

    Also, you have a typo in the port, Postgres use 5432 by default, not 54321

提交回复
热议问题