How to set database address?

I’m currently trying to run keycloak in docker with an external database.
I’m following this link: Keycloak - Server - Running Keycloak in a container

I keep getting a “Connection to localhost:5432 refused” error but I never set my database address to localhost and I actually don’t see a database address env variable.
The only variable I see that could set the database address is KC_DB_URL and it’s set to the correct postgres container name.

So how do I actually set the database address in this new Quarkus version?
Is there any documentation or reference about these environment variables? I found a lot but for the WildFly version.

1 Like

I got it working by using this URL format: jdbc:postgresql://my-postgresql-host:5432/keycloak-database-name. It is described when you click to expand the db-url config option in the docs, which is a little bit hidden.

2 Likes

Using these settings worked for me (using MariaBD):
KC_DB: mariadb
KC_DB_URL: jdbc:mariadb://ip or container name:3306/keycloak
KC_DB_USERNAME: keycloak
KC_DB_PASSWORD: your password

1 Like

To: joerijansen,

Thank you so much!!!
Before I came across your example, I spent a lot of times.
Many of the examples explained by others, as you pointed out, explain the method applied in keycloak ver. 16 as an example, but the problem was solved by the way you pointed out.

@joerijansen , I still getting error when I am run rke2 cluster and deployed postgresql container with its cluster-ip service on port 5432 and now trying to deploy keycloak container within same cluster however, keycloak pod logs shows:

cannot resolve host “postgresql”; lookup postgresql on 10.23.0.05:53: no such host

my keycloak config in keycloak deployment yaml file:
KC_DB: “postgres”
KC_DB_URL: “jdbc:postgresql://localhost:5432/keycloak”
KC_DB_USERNAME: “*****”
KC_DB_PASSWORD: “****”

I have tried with different values in KC_DB_URL but still not working, not sure what causing this?
rke2 coredns service is working fine.
Am I missing something here?

@monu the problem you have is pure a rke2 issue: Keycloak unable to resolve the DNS hostname is not a Keycloak issue. Not having much experience with rke2, I am not able to help you out on this point…

1 Like

@joerijansen , rke is not a new thing, under the hood, it spins same kubernetes API controal planes components such as coreDNS, kube API server etc…

Wondering if you have deployed keycloak container image in kubernetes cluster with its own separate postgresql database?

in my case, both keycloak and postgresql are running in separate containers on different pods on the nodes?