无法连接到Docker postgres容器-Scala

时间:2020-08-13 11:05:16

标签: java scala docker doobie

我创建了一个名为Job-board的服务,我希望它运行并与postgres容器对话。我不确定是否应该使用sbt运行工作板?还是应该使用docker-compose来与Docker一起运行这两个服务?

何时使用SBT以及在容器中运行?

我一直收到以下连接错误,我尝试使用连接网址,但是没有运气。

我不确定application.config在这一切中起什么作用,以及它与dockerFile和docker-compose的关系。

如果您需要更多详细信息,这里是github存储库:https://github.com/fullStackRyan/job-board

Starting job-board_postgres_1 ... done
Starting job-board_job-board_1 ... done
Attaching to job-board_postgres_1, job-board_job-board_1
postgres_1   | 
postgres_1   | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres_1   | 
postgres_1   | 2020-08-13 10:57:43.540 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres_1   | 2020-08-13 10:57:43.540 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres_1   | 2020-08-13 10:57:43.542 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1   | 2020-08-13 10:57:43.555 UTC [21] LOG:  database system was shut down at 2020-08-13 10:57:29 UTC
postgres_1   | 2020-08-13 10:57:43.557 UTC [1] LOG:  database system is ready to accept connections
job-board_1  | [info] welcome to sbt 1.3.13 (Oracle Corporation Java 1.8.0_222)
job-board_1  | [info] loading project definition from /usr/src/job-board/project
job-board_1  | [info] loading settings for project job-board from build.sbt ...
job-board_1  | [info] set current project to job-board (in build file:/usr/src/job-board/)
job-board_1  | [warn] insecure HTTP request is deprecated 'http://repo.typesafe.com/typesafe/releases/'; switch to HTTPS or opt-in as ("Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/").withAllowInsecureProtocol(true)
job-board_1  | [info] running io.github.jobboard.Main 
job-board_1  | 10:57:57.456 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - HikariPool-1 - configuration:
job-board_1  | 10:57:57.468 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - allowPoolSuspension.............false
job-board_1  | 10:57:57.468 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - autoCommit......................true
job-board_1  | 10:57:57.468 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - catalog.........................none
job-board_1  | 10:57:57.469 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - connectionInitSql...............none
job-board_1  | 10:57:57.469 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - connectionTestQuery.............none
job-board_1  | 10:57:57.469 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - connectionTimeout...............30000
job-board_1  | 10:57:57.470 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - dataSource......................none
job-board_1  | 10:57:57.470 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceClassName.............none
job-board_1  | 10:57:57.470 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceJNDI..................none
job-board_1  | 10:57:57.471 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceProperties............{password=<masked>}
job-board_1  | 10:57:57.471 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - driverClassName.................none
job-board_1  | 10:57:57.471 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - healthCheckProperties...........{}
job-board_1  | 10:57:57.472 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - healthCheckRegistry.............none
job-board_1  | 10:57:57.472 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - idleTimeout.....................600000
job-board_1  | 10:57:57.472 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - initializationFailTimeout.......1
job-board_1  | 10:57:57.473 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - isolateInternalQueries..........false
job-board_1  | 10:57:57.473 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - jdbcUrl.........................postgres://admin:password@postgres:5432/job-board
job-board_1  | 10:57:57.473 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - leakDetectionThreshold..........0
job-board_1  | 10:57:57.474 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - maxLifetime.....................1800000
job-board_1  | 10:57:57.474 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - maximumPoolSize.................10
job-board_1  | 10:57:57.474 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - metricRegistry..................none
job-board_1  | 10:57:57.475 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - metricsTrackerFactory...........none
job-board_1  | 10:57:57.475 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - minimumIdle.....................10
job-board_1  | 10:57:57.475 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - password........................<masked>
job-board_1  | 10:57:57.476 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - poolName........................"HikariPool-1"
job-board_1  | 10:57:57.476 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - readOnly........................false
job-board_1  | 10:57:57.476 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - registerMbeans..................false
job-board_1  | 10:57:57.476 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - scheduledExecutor...............none
job-board_1  | 10:57:57.477 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - schema..........................none
job-board_1  | 10:57:57.477 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - threadFactory...................internal
job-board_1  | 10:57:57.478 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - transactionIsolation............default
job-board_1  | 10:57:57.478 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - username........................"admin"
job-board_1  | 10:57:57.478 [ForkJoinPool-1-worker-13] DEBUG com.zaxxer.hikari.HikariConfig - validationTimeout...............5000
job-board_1  | 10:57:57.482 [ForkJoinPool-1-worker-13] INFO  com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
job-board_1  | java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=postgres://admin:password@postgres:5432/job-board
job-board_1  |  at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:112)
job-board_1  |  at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:336)
job-board_1  |  at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:109)
job-board_1  |  at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:108)
job-board_1  |  at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81)
job-board_1  |  at io.github.jobboard.database.Database$.transactor(Database.scala:20)
job-board_1  |  at io.github.jobboard.Main$$anonfun$1.apply(Main.scala:34)
job-board_1  |  at io.github.jobboard.Main$$anonfun$1.apply(Main.scala:33)
job-board_1  |  at fs2.Stream$$anonfun$flatMap$extension$1.apply(Stream.scala:1080)
job-board_1  |  at fs2.Stream$$anonfun$flatMap$extension$1.apply(Stream.scala:1073)
job-board_1  |  at fs2.internal.FreeC$$anonfun$flatMap$1.apply(FreeC.scala:33)
job-board_1  |  at fs2.internal.FreeC$$anonfun$flatMap$1.apply(FreeC.scala:30)
job-board_1  |  at fs2.internal.FreeC$ViewL$.mk(FreeC.scala:214)
job-board_1  |  at fs2.internal.FreeC$ViewL$.apply(FreeC.scala:206)
job-board_1  |  at fs2.internal.FreeC.viewL(FreeC.scala:67)
job-board_1  |  at fs2.internal.Algebra$.fs2$internal$Algebra$$go$1(Algebra.scala:214)
job-board_1  |  at fs2.internal.Algebra$$anonfun$fs2$internal$Algebra$$go$1$4$$anonfun$apply$5$$anonfun$apply$7.apply(Algebra.scala:260)
job-board_1  |  at fs2.internal.Algebra$$anonfun$fs2$internal$Algebra$$interruptGuard$1$1.apply(Algebra.scala:230)
job-board_1  |  at fs2.internal.Algebra$$anonfun$fs2$internal$Algebra$$interruptGuard$1$1.apply(Algebra.scala:229)
job-board_1  |  at cats.effect.internals.IORunLoop$.cats$effect$internals$IORunLoop$$loop(IORunLoop.scala:139)
job-board_1  |  at cats.effect.internals.IORunLoop$.startCancelable(IORunLoop.scala:41)
job-board_1  |  at cats.effect.internals.IOBracket$BracketStart.run(IOBracket.scala:86)
job-board_1  |  at cats.effect.internals.Trampoline.cats$effect$internals$Trampoline$$immediateLoop(Trampoline.scala:70)
job-board_1  |  at cats.effect.internals.Trampoline.startLoop(Trampoline.scala:36)
job-board_1  |  at cats.effect.internals.TrampolineEC$JVMTrampoline.cats$effect$internals$TrampolineEC$JVMTrampoline$$super$startLoop(TrampolineEC.scala:93)
job-board_1  |  at cats.effect.internals.TrampolineEC$JVMTrampoline$$anonfun$startLoop$1.apply$mcV$sp(TrampolineEC.scala:93)
job-board_1  |  at cats.effect.internals.TrampolineEC$JVMTrampoline$$anonfun$startLoop$1.apply(TrampolineEC.scala:93)
job-board_1  |  at cats.effect.internals.TrampolineEC$JVMTrampoline$$anonfun$startLoop$1.apply(TrampolineEC.scala:93)
job-board_1  |  at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:72)
job-board_1  |  at cats.effect.internals.TrampolineEC$JVMTrampoline.startLoop(TrampolineEC.scala:92)
job-board_1  |  at cats.effect.internals.Trampoline.execute(Trampoline.scala:43)
job-board_1  |  at cats.effect.internals.TrampolineEC.execute(TrampolineEC.scala:44)
job-board_1  |  at cats.effect.internals.IOBracket$BracketStart.apply(IOBracket.scala:72)
job-board_1  |  at cats.effect.internals.IOBracket$BracketStart.apply(IOBracket.scala:52)
job-board_1  |  at cats.effect.internals.IORunLoop$.cats$effect$internals$IORunLoop$$loop(IORunLoop.scala:136)
job-board_1  |  at cats.effect.internals.IORunLoop$.start(IORunLoop.scala:34)
job-board_1  |  at cats.effect.internals.IOBracket$$anonfun$apply$1.apply(IOBracket.scala:44)
job-board_1  |  at cats.effect.internals.IOBracket$$anonfun$apply$1.apply(IOBracket.scala:34)
job-board_1  |  at cats.effect.internals.IORunLoop$RestartCallback.start(IORunLoop.scala:341)
job-board_1  |  at cats.effect.internals.IORunLoop$.cats$effect$internals$IORunLoop$$loop(IORunLoop.scala:119)
job-board_1  |  at cats.effect.internals.IORunLoop$RestartCallback.signal(IORunLoop.scala:355)
job-board_1  |  at cats.effect.internals.IORunLoop$RestartCallback.apply(IORunLoop.scala:376)
job-board_1  |  at cats.effect.internals.IORunLoop$RestartCallback.apply(IORunLoop.scala:316)
job-board_1  |  at cats.effect.internals.IOShift$Tick.run(IOShift.scala:36)
job-board_1  |  at scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121)
job-board_1  |  at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
job-board_1  |  at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
job-board_1  |  at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
job-board_1  |  at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
job-board_1  | Caused by: java.sql.SQLException: No suitable driver
job-board_1  |  at java.sql.DriverManager.getDriver(DriverManager.java:315)
job-board_1  |  at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:104)
job-board_1  |  ... 48 more
job-board_1  | 
job-board_1  | Exception: sbt.TrapExitSecurityException thrown from the UncaughtExceptionHandler in thread "run-main-0"
job-board_1  | [error] Nonzero exit code: 1
job-board_1  | [error] (Compile / run) Nonzero exit code: 1
job-board_1  | [error] Total time: 4 s, completed Aug 13, 2020 10:57:57 AM
job-board_job-board_1 exited with code 1

1 个答案:

答案 0 :(得分:1)

看起来您的postgre网址错误。根据此文档,我看不到Postgre.POSTGRES_URL环境var。 https://hub.docker.com/_/postgres

在工作板上:您的POSTGRES_URL应该看起来像 jdbc:{驱动程序}:// {主机}:{端口} / {db}