# How to set redis DB ID in Docker container?

**URL:** https://meta.discourse.org/t/how-to-set-redis-db-id-in-docker-container/56267
**Category:** Self-hosting
**Created:** [January 24, 2017, 12:30pm UTC](https://meta.discourse.org/t/how-to-set-redis-db-id-in-docker-container/56267 "2017-01-24T12:30:23Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![TomekB](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tomekb/32/66593_2.png) [@TomekB](https://meta.discourse.org/u/TomekB)
#### Post date: [January 24, 2017, 12:30pm UTC](https://meta.discourse.org/t/how-to-set-redis-db-id-in-docker-container/56267/1 "2017-01-24T12:30:23Z")

</div>

I have one data container and I would like to use several web\_only containers (several forums on separate servers). How to I pass a DB ID to web\_only container so that multiple forums use their own cache?

Without this the stats reported in Admin → Reports are mixed up between different forums.

---

<div class="post-metadata">

### Author: ![rluba](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rluba/32/122710_2.png) [@rluba](https://meta.discourse.org/u/rluba)
#### Post date: [October 17, 2018, 2:40pm UTC](https://meta.discourse.org/t/how-to-set-redis-db-id-in-docker-container/56267/2 "2018-10-17T14:40:29Z")

</div>

I’ve got the same issue. I have an existing redis cluster (with replication and failover) that I want Discourse to use, but I can’t find a way to tell Discourse which database index to use.

---

<div class="post-metadata">

### Author: ![rluba](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rluba/32/122710_2.png) [@rluba](https://meta.discourse.org/u/rluba)
#### Post date: [October 17, 2018, 2:46pm UTC](https://meta.discourse.org/t/how-to-set-redis-db-id-in-docker-container/56267/3 "2018-10-17T14:46:32Z")

</div>

I’ve found the corresponding setting via [this answer](https://meta.discourse.org/t/external-database-env-vars-not-documented-external-pg-port-external-redis-env-vars/90879/2). It’s hidden in `discourse_defaults.conf`:

> <https://github.com/discourse/discourse/blob/ee18d9ace09b0b2919867c905cda72f85f61efb4/config/discourse_defaults.conf#L115>

It’s called `redis_db`, so the corresponding setting in the container yaml should be `DISCOURSE_REDIS_DB`.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [October 17, 2018, 11:28pm UTC](https://meta.discourse.org/t/how-to-set-redis-db-id-in-docker-container/56267/4 "2018-10-17T23:28:14Z")

</div>

Definitely do not do anything like this 🔥 . Message Bus which is responsible for long polling relies on pub/sub, pub/sub is always on “db 0” not configurable.

If you try to co-host multiple Discourses on one Redis DB expect some very major amount of breakage.

---

<div class="post-metadata">

### Author: ![rluba](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rluba/32/122710_2.png) [@rluba](https://meta.discourse.org/u/rluba)
#### Post date: [October 18, 2018, 6:32am UTC](https://meta.discourse.org/t/how-to-set-redis-db-id-in-docker-container/56267/5 "2018-10-18T06:32:06Z")

</div>

Thank you for the warning! 🙇‍♂️

---

<div class="post-metadata">

### Author: ![ryanerwin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ryanerwin/32/94589_2.png) [@ryanerwin](https://meta.discourse.org/u/ryanerwin)
#### Post date: [June 5, 2020, 1:49pm UTC](https://meta.discourse.org/t/how-to-set-redis-db-id-in-docker-container/56267/6 "2020-06-05T13:49:49Z")

</div>

@sam is your warning 🔥 from 2018 about the message bus exclusively linked to Redis `db 0` still accurate, or can we use now a different redis instance database ID to host different discourse instances?

I noticed in the [multisite-configuration-with-docker](https://meta.discourse.org/t/multisite-configuration-with-docker/14084) howto, there is a `db_id: 2` defined, I thought that may refer to the redis database ID, thus this inquiry 🧐

```plaintext
         secondsite:
           adapter: postgresql
           database: b_discourse
           pool: 25
           timeout: 5000
           db_id: 2
           host_names:
             - b.discourse.example.com

```

> [@TomekB](#):
>
> Without this the stats reported in Admin → Reports are mixed up between different forums

> [@rluba](#):
>
> It’s called `redis_db` , so the corresponding setting in the container yaml should be `DISCOURSE_REDIS_DB` .

> [@sam](#):
>
> Definitely do not do anything like this 🔥 . Message Bus which is responsible for long polling relies on pub/sub, pub/sub is always on “db 0” not configurable.
> 
> If you try to co-host multiple Discourses on one Redis DB expect some very major amount of breakage.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [June 9, 2020, 8:08am UTC](https://meta.discourse.org/t/how-to-set-redis-db-id-in-docker-container/56267/7 "2020-06-09T08:08:07Z")

</div>

> [@ryanerwin](#):
>
> is your warning 🔥 from 2018 about the message bus exclusively linked to Redis `db 0` still accurate

Yes this is still 100% correct afaik, PUB/SUB in redis is tied to DB 0. Discourse multisite is designed to work fine with multiple instances talking to 1 redis with db 0.

> **[Develop with Redis](https://redis.io/docs/latest/develop/)**
>
> Learn how to develop with Redis

> Pub/Sub has no relation to the key space. It was made to not interfere with it on any level, including database numbers.
> 
> Publishing on db 10, will be heard by a subscriber on db 1.
