ktor mysql 容器连接被拒绝:驱动没有收到来自服务器的任何数据包

ktor mysql container connection refused : The driver has not received any packets from the server

提问人:AR Soft 提问时间:2/20/2023 更新时间:2/20/2023 访问量:192

问:

我有一个带有 ktor 项目的 mysql 服务的 docker-compose,当我与 mysql 工作台建立连接时它工作正常,但是当我尝试与我的 Web 服务连接时,它会给我抛出一个连接被拒绝错误。 驱动程序未收到来自服务器的任何数据包

主机、端口、用户和密码设置正确。

这是我的作文:

version: '3.9'

services:
  mysqldb:
    image: mysql:latest
#    platform: linux/amd64
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    container_name: ding-mysql-container
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: "%"
    ports:
      - "3307:3306"

  ktor:
    build: .
    image: com/ding-backen:0.0.7
#    platform: linux/amd64
    restart: always
    container_name: ding-main-container
    ports:
      - "8383:8383"
    environment:
      APP_ENV: local
    links:
      - mysqldb
    depends_on:
      - mysqldb

这是MySQL的Dockerfile:

EXPOSE 8383:8383
RUN mkdir /app
COPY ./build/libs/*-all.jar /app/ding-backend.jar
ENTRYPOINT ["java","-jar","/app/ding-backend.jar"]

这是 application.conf 文件

ktor {
    environment = local
    environment = ${?APP_ENV}

    baseUrl = ""
    baseUrl = ${?BASE_URL}

    deployment {
        port = 8383
        port = ${?PORT}
    }

    application {
        modules = [ com.ApplicationKt.module ]
    }

    local {
      db {
         host = "localhost"
         username = "root"
         password = "root"
         database = "ding_backend_db"
         port = 3307

         host = ${?MYSQL_ROOT_HOST}
         username = ${?MYSQL_USER}
         password = ${?MYSQL_PASSWORD}
         database = ${?MYSQL_DATABASE}
      }
    }

}

此错误消息见

com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: 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 com.zaxxer.hikari.pool.HikariPool.throwPoolInitializationException(HikariPool.java:596)
        at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:582)
        at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:100)
        at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81)
        at com.helper.DBHelper.buildDataSource(DBHelper.kt:33)
        at com.helper.DBHelper.<init>(DBHelper.kt:37)
        at com.helper.DBHelper$Companion$instance$2.invoke(DBHelper.kt:17)
        at com.helper.DBHelper$Companion$instance$2.invoke(DBHelper.kt:17)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at com.helper.DBHelper$Companion.getInstance(DBHelper.kt:17)
        at com.backend.model.Model.getDb(Model.kt:8)
        at com.backend.model.UserModel.getUserByEmail(UserModel.kt:24)
        at com.backend.controller.MobileApiController.addUser(MobileApiController.kt:48)
        at com.routes.RoutesKt$routes$1$1.invokeSuspend(Routes.kt:13)
        at com.routes.RoutesKt$routes$1$1.invoke(Routes.kt)
        at com.routes.RoutesKt$routes$1$1.invoke(Routes.kt)
        at io.ktor.server.routing.Route$buildPipeline$1$1.invokeSuspend(Route.kt:116)
        at io.ktor.server.routing.Route$buildPipeline$1$1.invoke(Route.kt)
        at io.ktor.server.routing.Route$buildPipeline$1$1.invoke(Route.kt)
        at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
        at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
        at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:98)
        at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77)
        at io.ktor.server.routing.Routing$executeResult$$inlined$execute$1.invokeSuspend(Pipeline.kt:478)
        at io.ktor.server.routing.Routing$executeResult$$inlined$execute$1.invoke(Pipeline.kt)
        at io.ktor.server.routing.Routing$executeResult$$inlined$execute$1.invoke(Pipeline.kt)
        at io.ktor.util.debug.ContextUtilsKt.initContextInDebugMode(ContextUtils.kt:17)
        at io.ktor.server.routing.Routing.executeResult(Routing.kt:190)
        at io.ktor.server.routing.Routing.interceptor(Routing.kt:64)
        at io.ktor.server.routing.Routing$Plugin$install$1.invokeSuspend(Routing.kt:140)
        at io.ktor.server.routing.Routing$Plugin$install$1.invoke(Routing.kt)
        at io.ktor.server.routing.Routing$Plugin$install$1.invoke(Routing.kt)
        at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
        at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
        at io.ktor.server.engine.BaseApplicationEngineKt$installDefaultTransformationChecker$1.invokeSuspend(BaseApplicationEngine.kt:123)
        at io.ktor.server.engine.BaseApplicationEngineKt$installDefaultTransformationChecker$1.invoke(BaseApplicationEngine.kt)
        at io.ktor.server.engine.BaseApplicationEngineKt$installDefaultTransformationChecker$1.invoke(BaseApplicationEngine.kt)
        at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
        at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
        at io.ktor.server.application.hooks.CallFailed$install$1$1.invokeSuspend(CommonHooks.kt:43)
        at io.ktor.server.application.hooks.CallFailed$install$1$1.invoke(CommonHooks.kt)
        at io.ktor.server.application.hooks.CallFailed$install$1$1.invoke(CommonHooks.kt)
        at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
        at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:264)
        at io.ktor.server.application.hooks.CallFailed$install$1.invokeSuspend(CommonHooks.kt:42)
        at io.ktor.server.application.hooks.CallFailed$install$1.invoke(CommonHooks.kt)
        at io.ktor.server.application.hooks.CallFailed$install$1.invoke(CommonHooks.kt)
        at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
        at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
        at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:98)
        at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77)
        at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1$invokeSuspend$$inlined$execute$1.invokeSuspend(Pipeline.kt:478)
        at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1$invokeSuspend$$inlined$execute$1.invoke(Pipeline.kt)
        at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1$invokeSuspend$$inlined$execute$1.invoke(Pipeline.kt)
        at io.ktor.util.debug.ContextUtilsKt.initContextInDebugMode(ContextUtils.kt:17)
        at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1.invokeSuspend(DefaultEnginePipeline.kt:118)
        at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1.invoke(DefaultEnginePipeline.kt)
        at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$1.invoke(DefaultEnginePipeline.kt)
        at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:120)
        at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:78)
        at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:98)
        at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77)
        at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1$invokeSuspend$$inlined$execute$1.invokeSuspend(Pipeline.kt:478)
        at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1$invokeSuspend$$inlined$execute$1.invoke(Pipeline.kt)
        at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1$invokeSuspend$$inlined$execute$1.invoke(Pipeline.kt)
        at io.ktor.util.debug.ContextUtilsKt.initContextInDebugMode(ContextUtils.kt:17)
        at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1.invokeSuspend(NettyApplicationCallHandler.kt:119)
        at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1.invoke(NettyApplicationCallHandler.kt)
        at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1.invoke(NettyApplicationCallHandler.kt)
        at kotlinx.coroutines.intrinsics.UndispatchedKt.startCoroutineUndispatched(Undispatched.kt:55)
        at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:112)
        at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126)
        at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
        at kotlinx.coroutines.BuildersKt.launch(Unknown Source)
        at io.ktor.server.netty.NettyApplicationCallHandler.handleRequest(NettyApplicationCallHandler.kt:37)
        at io.ktor.server.netty.NettyApplicationCallHandler.channelRead(NettyApplicationCallHandler.kt:29)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
        at io.netty.channel.AbstractChannelHandlerContext.access$600(AbstractChannelHandlerContext.java:61)
        at io.netty.channel.AbstractChannelHandlerContext$7.run(AbstractChannelHandlerContext.java:425)
        at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.ktor.server.netty.EventLoopGroupProxy$Companion.create$lambda$1$lambda$0(NettyApplicationEngine.kt:291)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

提前感谢您的任何帮助

mysql docker docker-compose 服务端 ktor

评论


答: 暂无答案