'How to use both Java in Docker and PostgreSQL database?

I am developing the Heroku toy app and want to use the PostgreSQL database to store configurations. I either see tutorials on how to use Java + PostgreSQL or Java on Docker.

I cannot find a way on how I can use Java in Docker + PostgreSQL.

NOTE: Database is a rather unimportant piece. It can be anything that can persist info such as Redis, other databases.

I looked through StackOverflow, tutorials, and Heroku doc but so far, no luck.

How can I connect to PostgreSQL from Java in Docker on Heroku?



Solution 1:[1]

To extend the @ErikMD answer, I have to add that there are many plugins for different databases available to establish the connection in the Java app, and there is no need to run Docker with DB inside but rather rely on plugins vendors.

I tried MySQL, PostgreSQL and never got any troubles with DB. If you move with plugins solutions, check their pricing model and limitations to avoid getting into billing trouble. Also, some plugins provide older databases, and you may have to put more effort into resolving correct library versions.

GUIDE:

  • choose DB plugin
  • run heroku config -a <app_name> to obtain db credentials
  • put them into application.properties or application.yml
  • voila, you connected to DB

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dmytro Chasovskyi