Docker, Springboot and Mysql : com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

后端 未结 2 1012
被撕碎了的回忆
被撕碎了的回忆 2021-01-27 10:51

I try to run a Springboot app with mysql connection on Docker. Without docker, it works well. But when I try to deploy on a container, I have com.mysql.cj.exceptions.CJCom

2条回答
  •  耶瑟儿~
    2021-01-27 11:43

    As your Spring Boot application is also launched in a docker image, you can't used the port exposed by docker, but instead you need to use the original port of the image.

    In application.properties you need to use:

    spring.datasource.url = jdbc:mysql://mysql:3306/db
    

提交回复
热议问题