0

I am trying to connect to the heroku postgres database I provisioned (not a docker image), from a docker app I deployed to heroku. When I push to heroku the image builds fine but when the app starts I get an error. It seems like the JDBC_DATABASE_URL is not being injected into the docker container, but I don't know how to get it to work.

Here is my code:

heroku.yml

build:
  docker:
    web: Dockerfile

Dockerfile

FROM openjdk:8-jdk-alpine
COPY build/libs/myapp-0.0.1-SNAPSHOT.jar app.jar
CMD ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

application.properties

## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url=${JDBC_DATABASE_URL}
spring.datasource.username=${JDBC_DATABASE_USERNAME}
spring.datasource.password=${JDBC_DATABASE_PASSWORD}

# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.show-sql=true


# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto=update

Exception

java.lang.RuntimeException: Driver org.postgresql.Driver claims to not accept jdbcUrl, ${JDBC_DATABASE_URL}
2
  • Maybe you should learn about Docker and Spring-Boot. By the way it's normal for you to get this RuntimeException, the var named {JDBC_DATABASE_URL} is called but never created before. Commented Oct 23, 2019 at 12:05
  • 2
    Thank you, @Zorglube. Can you point me to a resource where I can learn how to create the variable so I don't get the exception? Commented Oct 23, 2019 at 12:17

1 Answer 1

3

The JDBC_DATABASE_URL is set by the Heroku buildpack. When you're using Docker, you don't get to use buildpacks. If you want to mimic what the buildpack does you can copy this JDBC Profile script (but you'll have to update it manually if things ever change).

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks @codefinger! When using docker on heroku, is it better to use the postgres addon or a postgres docker image?
You can't run a postgres image on heroku
Does it mean that there are no correct way to run a spring boot app using a Postgres Heroku addons using docker on heroku?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.