简体   繁体   English

无法从主机连接到在 docker 下运行的 mysql 的套接字?

[英]Can't connect to the socket for mysql running under docker from the host?

I have mySQL running in a container.我在容器中运行 mySQL。 It and my app (in a different Docker container) seem to run fine.它和我的应用程序(在不同的 Docker 容器中)似乎运行良好。 I am now trying to use Jaspersoft's iReport to develop a report with.我现在正在尝试使用 Jaspersoft 的 iReport 来开发报告。 I have managed to get iReport up and running on the host, Ubuntu.我已经设法在主机 Ubuntu 上启动并运行 iReport。 The problem is accessing the database from the host.问题是从主机访问数据库。

This is required to use iReport and I just can't seem to get the connection working.这是使用 iReport 所必需的,我似乎无法使连接正常工作。 I tried looking at the mysql socket, but it is not in the normal place, since mySQL is in a Docker Container.我尝试查看 mysql 套接字,但它不在正常位置,因为 mySQL 位于 Docker 容器中。 I am also working on getting JasperReports server to run in another container.我也在努力让 JasperReports 服务器在另一个容器中运行。 But my problem is connecting from the host to the mySQL database running in Docker via an JDBC connection.但我的问题是通过 JDBC 连接从主机连接到在 Docker 中运行的 mySQL 数据库。

here is the docker-compose.yml https://drive.google.com/open?id=1CY_tPmnot3zSab0BtLE1fJUC7sdD2tyA这是 docker-compose.yml https://drive.google.com/open?id=1CY_tPmnot3zSab0BtLE1fJUC7sdD2tyA

The connection that iReports has chosen is jdbc:mysql://localhost/substantiator. iReports 选择的连接是 jdbc:mysql://localhost/substantiator。 When I try to "test" this with the iReport database test button I get a popup that asks for password.当我尝试使用 iReport 数据库测试按钮“测试”它时,我收到一个要求输入密码的弹出窗口。 I have tried using the same user/password combo that works from my app.我尝试使用与我的应用程序相同的用户/密码组合。 It fails with: SQL problems: Communication Link Failure.它失败了: SQL 问题:通信链接失败。 In researching this I am asked to update the mySQL socket path in a mysql cnf file.在研究这个时,我被要求更新 mysql cnf 文件中的 mySQL 套接字路径。 But in my installation the socket file doesn't exist (because it it in docker?).但是在我的安装中,套接字文件不存在(因为它在 docker 中?)。 So I am stumped.所以我很难过。 I am considering moving over to mariaDB.我正在考虑转移到 mariaDB。 Any ideas?有任何想法吗?

嗨,您的 MySql 容器从主机公开端口 3306,您可以使用 localhost 进行连接,但是对于某些外部服务,您需要使用主机 IP 地址,并确保端口 3306 对外公开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM