java – 两个docker容器之间的通信问题
我是docker的新手,我正在尝试将运行到我的boot-example docker容器中的spring boot app连接到运行到端口6603上的mymysql docker容器的mysql服务器,两者都运行在同一台机器上.事实是:如果我将我的spring-boot应用程序连接到mymysql docker容器以便与数据库通信,我没有错误,一切正常.
当我将我的spring启动应用程序移动到我的启动示例容器并尝试与我的mymysql容器进行通信(通过Hibernate)时,我收到此错误:
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
它工作正常,直到我的春季启动应用程序在端口8082上的docker容器中运行(在正确构建docker镜像之后):
docker run -it -p 8082:8083 boot-example