最新Docker镜像在连接MYSQL时抛出错误



我一直在尝试做一个POC使用Liquibase docker图像连接到MYSQL实例化和发布DB更改。我一直在看这些文章

https://docs.liquibase.com/workflows/liquibase-community/using-liquibase-and-docker.htmlhttps://hub.docker.com/r/liquibase/liquibasehttps://github.com/Inkimar/liquibase-example -示例Repo

然而,我总是得到下面的错误->

**Connection could not be created to jdbc:mysql://localhost:3306/denmark with driver 
com.mysql.cj.jdbc.Driver.  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.
liquibase.exception.CommandExecutionException: liquibase.exception.LiquibaseException: 
Unexpected error running Liquibase: liquibase.exception.DatabaseExcepti
on: liquibase.exception.DatabaseException: Connection could not be created to 
jdbc:mysql://localhost:3306/denmark with driver com.mysql.cj.jdbc.Driver.  
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 liquibase.command.CommandScope.execute(CommandScope.java:163)
at liquibase.integration.commandline.CommandRunner.call(CommandRunner.java:51)
at liquibase.integration.commandline.CommandRunner.call(CommandRunner.java:21)
at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
at picocli.CommandLine.access$1300(CommandLine.java:145)
at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent
(CommandLine.java:2358)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2314)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
at picocli.CommandLine.execute(CommandLine.java:2078)
at liquibase.integration.commandline.LiquibaseCommandLine.lambda$execute$1
(LiquibaseCommandLine.java:336)
at liquibase.Scope.child(Scope.java:189)
at liquibase.Scope.child(Scope.java:165)
at liquibase.integration.commandline.LiquibaseCommandLine.execute
(LiquibaseCommandLine.java:301)
at liquibase.integration.commandline.LiquibaseCommandLine.main
(LiquibaseCommandLine.java:90)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at liquibase.integration.commandline.LiquibaseLauncher.main(LiquibaseLauncher.java:91)**

任何运气或指针是高度赞赏。我试过使用MYSQL 5.7和8。X版本,但运气不好。

**无法使用驱动程序创建到jdbc:mysql://localhost:3306/denmark的连接

我猜你正在运行两个容器,一个运行Liquibase,一个运行MySQL。对吗?你不能使用"localhost"在Liquibase容器内,因为每个容器都有一个环回接口。当您运行容器并使用您的本地网络地址时,转发端口(-p 3306:3306)。192.168.10.

另一个选择是使用docker-compose(这样它们就在同一个虚拟网络上)并使用主机名进行连接。

相关内容