【发布时间】:2018-07-15 03:55:54
【问题描述】:
我是 docker 新手,我正在尝试将运行在 boot-example docker 容器中的 spring boot 应用程序连接到运行在 mymysql 中的 mysql 服务器6603 端口上的 docker 容器,两者都在同一台物理机器上运行。 事实是:如果我将我的 spring-boot 应用程序连接到我的 mymysql docker 容器以便与数据库通信,我不会收到任何错误,并且一切正常。
当我将 Spring Boot 应用程序 移动到我的 boot-example 容器中并尝试(通过 Hibernate)与我的 mymysql 容器进行通信时,然后我得到这个错误:
2018-02-05 09:58:38.912 ERROR 1 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_111]
我的spring boot application.properties是:
server.port=8083
spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.url=jdbc:mysql://localhost:6603/mydockerdb
spring.datasource.username=root
spring.datasource.password=mypassword
在我的 spring boot 应用程序在端口 8082 上的 docker 容器中运行之前,它可以正常工作,(在正确构建 docker 映像之后):
docker run -it -p 8082:8083 boot-example
【问题讨论】:
标签: java mysql spring docker spring-boot