0

So I have this application that connects to DB via simple JDBC written in Scala. Everything works fine until I'm trying to run it inside Docker container, there I'm getting the infamous Error during processing of request: 'No suitable driver found for "jdbc:postgresql://0.0.0.0:5439/dev" I've built a fat jar and when I'm running it on my machine - everything works fine, but the same fat jar that has been put inside docker container via

FROM java:8

COPY target/scala-2.13/loader-0.1.jar /fatjar.jar

CMD ["java", "-jar", "fatjar.jar"]

just can't connect. When I'm trying to debug - I see that driver is there:

  val dm = DriverManager.getDrivers()

  while (dm.hasMoreElements()) {
    println(dm.nextElement().getClass())
  }

spits out the same output both on my machine and inside docker. Can anyone point me to a possible piece that I'm missing?

Sonac
  • 58
  • 1
  • 7
  • Are you sure that `fatjar` has a valid Postgres driver in it? Maybe it works on your machine because you installed that driver on a global location that is always on the classpath. – Luis Miguel Mejía Suárez Nov 06 '20 at 20:07
  • 1
    debugging print spits me the following list inside docker: `➜ loader : ✗ docker run -p 8080:8080 --env-file .testenv loader 19:48:16.257 [example-akka.actor.default-dispatcher-5] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started class org.h2.Driver class org.postgresql.Driver class com.amazon.redshift.jdbc.Driver 19:48:16.991 [main] INFO Main$ - Server online at http://localhost:8080/` which is the same as on my machine. i was also thinking that it might catching up driver somewhere on my machine, but dunno, i have it in my sbt dependencies and i don't exclude anything – Sonac Nov 06 '20 at 20:12
  • 1
    This post might be helpful for you https://stackoverflow.com/questions/1911253/the-infamous-java-sql-sqlexception-no-suitable-driver-found – Boris Azanov Nov 07 '20 at 06:02
  • check your db url, it might be reason – Boris Azanov Nov 07 '20 at 06:04
  • 1
    Your JDBC url seems to be missing the database name, also 0.0.0.0 is not a valid IP address to connect to; if you want to connect to the local machine, use 127.0.0.1 – Mark Rotteveel Nov 07 '20 at 09:10
  • 1
    sorry, i've cut it out initially, added back to avoid confusion. i've tried using different urls, like some open RDS with DNS and again, it works fine on my machine, but not inside docker – Sonac Nov 07 '20 at 20:55

1 Answers1

1

Ok, so in the end the issue was fixed by moving from redshift driver (I need to actually connect to redshift) to postgres one "org.postgresql" % "postgresql" % "42.1.1" and with that in dependencies and having actually postgresql conn string I was able to solve my issue.

Sonac
  • 58
  • 1
  • 7