【发布时间】:2018-05-11 23:10:15
【问题描述】:
我已经看到了很多关于这个问题的答案,我今天正在尝试解决我的问题。 (我已经花了 2 天以上的时间,但仍然一无所知)。
这是我的情况:
在我的 Mac 10.13.1 上
MySQL 使用一个 docker 容器运行,我设置了所有这些权限。
docker exec -it mysql bash==>cd /etc=> 我在其中找到了一个my.cnf文件,我在其中添加了bind-address=127.0.0.1我有一个本地 MySQL 工作台,它能够连接到这个 MySQL 服务器
127.0.0.1:3306并从数据库中获取结果。-
但是,当我的应用程序在第二个 Docker 容器中启动时,我无法使其连接到另一个容器上的 MySQL 数据库。 这是我在应用启动期间使用的命令部分:
docker run -d ... -e DB_URL=jdbc:mysql://127.0.0.1:3306/mydatabase --name myApp --restart=always --link mysql myApp_t:latest
但是一旦 myApp 启动,我可以从它的日志中找到 msg:
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]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_111]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_111]
...
任何线索我还可以做什么?
【问题讨论】:
标签: mysql docker jdbc containers