# DB\_ADDR unbound variable error

**URL:** <https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077>\
**Category:** Configuring the server\
**Created:** [April 9, 2020, 11:16am UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077 "2020-04-09T11:16:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jominga](https://avatars.discourse-cdn.com/v4/letter/j/e56c9b/32.png) [@jominga](https://forum.keycloak.org/u/jominga)\
**Post date:** [April 9, 2020, 11:16am UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/1 "2020-04-09T11:16:18Z")

</div>

Hello,

I am trying to connec keycloak to a PostgreSqL database. To do this I am following the instructions in [https://hub.docker.com/r/jboss/keycloak/](https://hub.docker.com/r/jboss/keycloak/).

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

How can I solve this?

---

<div class="post-metadata">

**Author:** ![zonaut](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/zonaut/32/666_2.png) [@zonaut](https://forum.keycloak.org/u/zonaut)\
**Post date:** [April 9, 2020, 11:50am UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/2 "2020-04-09T11:50:40Z")

</div>

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/](https://hub.docker.com/r/jboss/keycloak/)

Maybe also take a look at docker-compose.  
Example:

```
version: '3.7'

services:
  postgres:
      image: postgres:12.2
      container_name: postgres
      environment:
        POSTGRES_DB: keycloak
        POSTGRES_USER: keycloak
        POSTGRES_PASSWORD: password

  keycloak:
      image: jboss/keycloak:9.0.2
      container_name: keycloak
      environment:
        DB_VENDOR: POSTGRES
        DB_ADDR: postgres
        DB_DATABASE: keycloak
        DB_USER: keycloak
        DB_PASSWORD: password
        KEYCLOAK_USER: admin
        KEYCLOAK_PASSWORD: password
        PROXY_ADDRESS_FORWARDING: "true"
      ports:
        - 8080:8080
      depends_on:
        - postgres

  mailhog:
    image: mailhog/mailhog:latest
    container_name: mailhog
    ports:
      - "8025:8025"
```

---

<div class="post-metadata">

**Author:** ![jominga](https://avatars.discourse-cdn.com/v4/letter/j/e56c9b/32.png) [@jominga](https://forum.keycloak.org/u/jominga)\
**Post date:** [April 9, 2020, 12:40pm UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/3 "2020-04-09T12:40:58Z")

</div>

Hello,

thanks for your reply. If I run the following I get the same error:

> docker run --name keycloak --net keycloak-network jboss/keycloak -e DB\_USER=keycloak -e DB\_PASSWORD=password, -e DB\_VENDOR=POSTGRES, -e DB\_ADDR=postgres, -e DB\_DATABASE=keycloak, -e KEYCLOAK\_USER=keycloak, -e KEYCLOAK\_PASSWORD=password, PROXY\_ADDRESS\_FORWARDING=true

---

<div class="post-metadata">

**Author:** ![zonaut](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/zonaut/32/666_2.png) [@zonaut](https://forum.keycloak.org/u/zonaut)\
**Post date:** [April 9, 2020, 2:23pm UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/4 "2020-04-09T14:23:26Z")

</div>

You can’t put comma’s in there

---

<div class="post-metadata">

**Author:** ![rhuankarlus](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/rhuankarlus/32/653_2.png) [@rhuankarlus](https://forum.keycloak.org/u/rhuankarlus)\
**Post date:** [April 13, 2020, 1:02am UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/5 "2020-04-13T01:02:58Z")

</div>

I’m having the same issue.  
Here are the steps to reproduce it:

```
* docker network create keycloak-network
* docker run -d --name postgres --net keycloak-network -e POSTGRES_DB=keycloak -e POSTGRES_USER=keycloak -e POSTGRES_PASSWORD=password postgres
* docker run --rm --name keycloak --net keycloak-network -p 8080:8080 jboss/keycloak -e DB_USER=keycloak -e DB_PASSWORD=password -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin -e DB_ADDR=postgres -e DB_VENDOR=postgres

```

The result:

> /opt/jboss/tools/docker-entrypoint.sh: line 156: DB\_ADDR: unbound variable

Does someone know how to solve it?

---

<div class="post-metadata">

**Author:** ![rhuankarlus](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/rhuankarlus/32/653_2.png) [@rhuankarlus](https://forum.keycloak.org/u/rhuankarlus)\
**Post date:** [April 13, 2020, 1:21am UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/6 "2020-04-13T01:21:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![darrensapalo](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/darrensapalo/32/854_2.png) [@darrensapalo](https://forum.keycloak.org/u/darrensapalo)\
**Post date:** [August 10, 2020, 12:37pm UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/7 "2020-08-10T12:37:06Z")

</div>

For full disclosure, the format as @rhuankarlus and @zonaut have described it should look like:

```auto
docker run --name keycloak --net keycloak-network \
    -e DB_USER=keycloak -e DB_PASSWORD=password \
    -e DB_VENDOR=POSTGRES \
    -e DB_ADDR=postgres \
    -e DB_DATABASE=keycloak \
    -e KEYCLOAK_USER=keycloak \
    -e KEYCLOAK_PASSWORD=password \
    -e PROXY_ADDRESS_FORWARDING=true \
    jboss/keycloak 

```

1. It doesn’t use commas in between environment variables.
2. It has the target docker image at the end of the command.
3. (Optional) I used `\` to denote new lines when running the command in your shell, for readability purposes.

---

<div class="post-metadata">

**Author:** ![sakoht](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/sakoht/32/1243_2.png) [@sakoht](https://forum.keycloak.org/u/sakoht)\
**Post date:** [August 14, 2020, 4:24pm UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/8 "2020-08-14T16:24:34Z")

</div>

This is great. Someone should update the install instructions, b/c they are broken without these additions:  
[https://www.keycloak.org/getting-started/getting-started-docker](https://www.keycloak.org/getting-started/getting-started-docker)

---

<div class="post-metadata">

**Author:** ![sakoht](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/sakoht/32/1243_2.png) [@sakoht](https://forum.keycloak.org/u/sakoht)\
**Post date:** [August 15, 2020, 12:16am UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/9 "2020-08-15T00:16:27Z")

</div>

> [@darrensapalo](#):
>
> ```auto
> docker run --name keycloak --net keycloak-network \
> -e DB_USER=keycloak -e DB_PASSWORD=password \
> -e DB_VENDOR=POSTGRES \
> -e DB_ADDR=postgres \
> -e DB_DATABASE=keycloak \
> -e KEYCLOAK_USER=keycloak \
> -e KEYCLOAK_PASSWORD=password \
> -e PROXY_ADDRESS_FORWARDING=true \
> jboss/keycloak 
> 
> ```

I get:

```auto
 (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([("subsystem" => "microprofile-metrics-smallrye")]): java.lang.NullPointerException

```

Can you indicate the exact docker image version that works for you?

I’m using the postgres:12 container for postgres.

---

<div class="post-metadata">

**Author:** ![jameshgrn](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@jameshgrn](https://forum.keycloak.org/u/jameshgrn)\
**Post date:** [August 15, 2020, 3:36pm UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/10 "2020-08-15T15:36:35Z")

</div>

I am having the exact same issue on install as @sakoht. Please help!

---

<div class="post-metadata">

**Author:** ![terexa](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@terexa](https://forum.keycloak.org/u/terexa)\
**Post date:** [November 4, 2020, 8:02am UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/11 "2020-11-04T08:02:02Z")

</div>

@sakoht try adding the JDBC\_PARAMS according to the DB that you are using. For example, I am using postgres and this worked for me:

```
docker run -p 8080:8080 --name keycloak --net keycloak-network \
    -e DB_USER=keycloak -e DB_PASSWORD=password \
    -e DB_VENDOR=POSTGRES \
    -e JDBC_PARAMS='connectTimeout=60' \
    -e DB_ADDR=postgres \
    -e DB_DATABASE=keycloak \
    -e KEYCLOAK_USER=keycloak \
    -e KEYCLOAK_PASSWORD=password \
    -e PROXY_ADDRESS_FORWARDING=true \
    quay.io/keycloak/keycloak:11.0.2
```

---

<div class="post-metadata">

**Author:** ![tempire](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/tempire/32/2189_2.png) [@tempire](https://forum.keycloak.org/u/tempire)\
**Post date:** [January 22, 2021, 5:34pm UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/12 "2021-01-22T17:34:40Z")

</div>

As per the instructions at [https://www.keycloak.org/getting-started/getting-started-docker](https://www.keycloak.org/getting-started/getting-started-docker), albeit with one necessary addition that they omitted:

docker run -it -p 8080:8080 -e KEYCLOAK\_USER=admin -e KEYCLOAK\_PASSWORD=admin -e DB\_VENDOR=h2 [quay.io/keycloak/keycloak:12.0.2](http://quay.io/keycloak/keycloak:12.0.2)

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.

---

<div class="post-metadata">

**Author:** ![lmsurpre](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/lmsurpre/32/1060_2.png) [@lmsurpre](https://forum.keycloak.org/u/lmsurpre)\
**Post date:** [February 23, 2021, 1:13pm UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/13 "2021-02-23T13:13:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gox9](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/gox9/32/2561_2.png) [@gox9](https://forum.keycloak.org/u/gox9)\
**Post date:** [March 5, 2021, 7:42pm UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/14 "2021-03-05T19:42:08Z")

</div>

Hello, I am a complete beginner. Following the instructions in the followin page to run keycloak as a docker container locally on a Mac:  
[https://www.keycloak.org/getting-started/getting-started-docker](https://www.keycloak.org/getting-started/getting-started-docker)

Just executed the first step.

```auto
docker run -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin quay.io/keycloak/keycloak:12.0.4

```

And I got this error:  
/opt/jboss/tools/docker-entrypoint.sh: line 165: DB\_ADDR: unbound variable

Could you please clearly state what prior steps should be done to successfully complete that setup?  
Thanks!!

---

<div class="post-metadata">

**Author:** ![jangaraj](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jangaraj/32/5175_2.png) [@jangaraj](https://forum.keycloak.org/u/jangaraj)\
**Post date:** [March 5, 2021, 7:52pm UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/15 "2021-03-05T19:52:46Z")

</div>

It was mentioned before (env variable `DB_VENDOR=h2` is the clue):

```auto
docker run --rm -p 8080:8080 \
  -e KEYCLOAK_USER=admin \
  -e KEYCLOAK_PASSWORD=admin \
  -e DB_VENDOR=h2 \
  quay.io/keycloak/keycloak:12.0.4

```

---

<div class="post-metadata">

**Author:** ![gox9](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/gox9/32/2561_2.png) [@gox9](https://forum.keycloak.org/u/gox9)\
**Post date:** [March 5, 2021, 7:54pm UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/16 "2021-03-05T19:54:58Z")

</div>

Thanks! That worked.  
Is it possible to update the webpage accordingly?  
Normally getting-started tutorials should work.

---

<div class="post-metadata">

**Author:** ![jangaraj](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/jangaraj/32/5175_2.png) [@jangaraj](https://forum.keycloak.org/u/jangaraj)\
**Post date:** [March 5, 2021, 8:00pm UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/17 "2021-03-05T20:00:33Z")

</div>

We are “community” here, not a “developers”, who have access to edit that page. Please open ticket [https://issues.jboss.org/browse/KEYCLOAK](https://issues.jboss.org/browse/KEYCLOAK) and help to make it better.

---

<div class="post-metadata">

**Author:** ![gox9](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/gox9/32/2561_2.png) [@gox9](https://forum.keycloak.org/u/gox9)\
**Post date:** [March 5, 2021, 8:10pm UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/18 "2021-03-05T20:10:13Z")

</div>

Thanks for guidance. Raised [KEYCLOAK-17351](https://issues.redhat.com/browse/KEYCLOAK-17351)

---

<div class="post-metadata">

**Author:** ![thequy](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/thequy/32/2639_2.png) [@thequy](https://forum.keycloak.org/u/thequy)\
**Post date:** [March 17, 2021, 9:23am UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/19 "2021-03-17T09:23:07Z")

</div>

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.

> docker run --rm --name keycloak-db --net keycloak-net -p 5432:5432 -v keycloak-12.0.4-vol:/var/lib/postgresql/data -e POSTGRES\_DB=keycloak -e POSTGRES\_USER=keycloak -e POSTGRES\_PASSWORD=keycloak postgres:13.2-alpine

> docker run --rm --name keycloak-app --net keycloak-net -p 8080:8080 -p 8443:8443 -e DB\_VENDOR=postgres -e DB\_ADDR=keycloak-db -e DB\_DATABASE=keycloak -e DB\_USER=keycloak -e DB\_PASSWORD=keycloak -e JDBC\_PARAMS=‘useSSL=false’ -e KEYCLOAK\_USER=admin -e KEYCLOAK\_PASSWORD=admin jboss/keycloak:12.0.4

`

---

<div class="post-metadata">

**Author:** ![oceanromain](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/oceanromain/32/3560_2.png) [@oceanromain](https://forum.keycloak.org/u/oceanromain)\
**Post date:** [July 16, 2021, 2:29pm UTC](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077/20 "2021-07-16T14:29:12Z")

</div>

keycloak use postgres

docker run -d --name postgres   
–restart=always   
-e DB\_ADDR=postgres   
-v /opt/postgres:/var/lib/postgresql/data   
–net keycloak-network   
-e POSTGRES\_DB=keycloak   
-e POSTGRES\_USER=keycloak   
-e POSTGRES\_PASSWORD=password   
postgres

docker run -d -p 8080:8080 -p 8443:8443   
–name keycloak   
–restart=always   
-e DB\_VENDOR=postgres   
-e DB\_ADDR=postgres   
-e DB\_USER=keycloak   
-e DB\_DATABASE=keycloak   
-e DB\_PASSWORD=password   
-e KEYCLOAK\_USER=admin   
-e KEYCLOAK\_PASSWORD=password   
–net keycloak-network   
jboss/keycloak

[Next page](https://forum.keycloak.org/t/db-addr-unbound-variable-error/2077.md?page=2)
