First I create a user defined network: docker network create keycloak-network
Then I start a PostgreSQL instance using the PostgreSQL docker image: docker run -d --name postgres --net keycloak-network -e POSTGRES_DB=keycloak -e POSTGRES_USER=keycloak -e POSTGRES_PASSWORD=password postgres
And lastly I try to run Keycloak instance: docker run --name keycloak --net keycloak-network jboss/keycloak -e DB_USER=keycloak -e DB_PASSWORD=password
However I get the following error:
/opt/jboss/tools/docker-entrypoint.sh: line 156: DB_ADDR: unbound variable
You forgot to set the DB_ADDR environment variable when starting keycloak. -e DB_ADDR=postgres also set -e DB_VENDOR=POSTGRES
Read the section Environment variables on https://hub.docker.com/r/jboss/keycloak/
Maybe also take a look at docker-compose.
Example:
I think Iāve found the solution after some tries. Them problem seems to be with Docker and not with Keycloak itself.
You need to pass the image name jboss/keycloak to the end of the whole command. Something like docker run <a bunch of environment variables> jboss/keycloak and it will work fine. Thanks a lot guys.
DB_VENDOR=h2 makes keycloak use an embedded database. No other containers or setup is required. This should be the default setting, but someone likely dropped the ball.
I was having the same issue (had to explicitly set DB_VENDOR to H2, which is supposed to be the default). I dug in a bit and found that this line in the docker-entrypoint.sh is to blame:
if (getent hosts postgres &>/dev/null); then
export DB_VENDOR="postgres"
In my case, the āgetent hosts postgresā is truthy because my host seems to be resolving āpostgresā to some weird akamai endpoint (no clue why).
Explicitly setting DB_VENDOR seems like a good idea to avoid this brittle db type detection algorithm.
We are ācommunityā here, not a ādevelopersā, who have access to edit that page. Please open ticket https://issues.jboss.org/browse/KEYCLOAK and help to make it better.
For me, I need added DB_VENDOR=postgres env. variable when I changed name of postgres container (Eg: keycloak-db).
Iām using postgres:13.2-alpine and jboss/keycloak:12.0.4 images.