无法连接到 Docker 的 postgres 容器 – Scala

huangapple go评论100阅读模式
英文:

Cannot Connect to Docker postgres container - Scala

问题

我已经创建了一个名为job-board的服务,我想让它运行并与Postgres容器通信。我不确定是否应该使用sbt运行job-board?还是应该使用docker-compose up来使用Docker运行两个服务?

什么时候使用SBT,什么时候在容器中运行?

我一直收到下面的连接错误,我已经尝试调整连接URL,但没有运气。

我不确定应用程序配置(application.config)在所有这些中扮演多大的角色,以及它与Docker文件和docker-compose的关系。

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

英文:

I have created a service called job-board I want it to run and talk to postgres container. I am not sure if I should run the job-board using sbt? or should I use docker-compose up to run both services with Docker?

When do you run with SBT and when running in containers?

I keep getting the below connection error, I have tried playing around with the connection urls but no luck.

I am unsure of how much role the application.config plays in all of this and how it relates to dockerFile and docker-compose.

Here is the github repo should you need more details: 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

得分: 1

It looks like your postgre URL is incorrect. According to this documentation, I don't see the Postgre.POSTGRES_URL environment variable. In the job-board, your POSTGRES_URL should appear as jdbc:{driver}://{host}:{port}/{db}.

英文:

Its look like your postgre url is wrong. According to this documentation I don`t see Postgre.POSTGRES_URL environment var. https://hub.docker.com/_/postgres

In job-board: your POSTGRES_URL should look like
jdbc:{driver}://{host}:{port}/{db}

huangapple
  • 本文由 发表于 2020年8月13日 19:05:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/63393791.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定