【发布时间】:2021-10-20 00:43:09
【问题描述】:
我有一个运行 Spring Boot 并使用 JDBC 连接到数据库的 Maven 容器。
我想连接到主机数据库
(主机:Ubuntu/18.04.5 LTS(仿生海狸))
(数据库:mysql Ver 14.14 Distrib 5.7.35,适用于使用 EditLine 包装器的 Linux (x86_64))
这是我的连接字符串
this.conn = DriverManager.getConnection("jdbc:mysql://172.24.0.1:3306/myDB?"+"user=xxxx&password=xxxx");
这是我的容器 IP
$ip route show
default via 172.24.0.1 dev eth0
172.24.0.0/16 dev eth0 proto kernel scope link src 172.24.0.10
我可以在 Maven 容器中使用 IP 172.24.0.1 或 172.17.0.1 进行 telnet 和 mysql 登录
$telnet 172.24.0.1 3306
Trying 172.24.0.1...
Connected to 172.24.0.1.
Escape character is '^]'.
telnet 172.17.0.1 3306
Trying 172.17.0.1...
Connected to 172.17.0.1.
Escape character is '^]'.
但是,我无法通过 JDBC 与 IP 172.24.0.1 或 172.17.0.1 连接。
【问题讨论】:
-
定义“无法连接”。
标签: java mysql spring-boot docker jdbc