# External database ENV VARs not documented (external PG Port, external Redis ENV VARs)

**URL:** https://meta.discourse.org/t/external-database-env-vars-not-documented-external-pg-port-external-redis-env-vars/90879
**Category:** Self-hosting
**Created:** [June 27, 2018, 3:19pm UTC](https://meta.discourse.org/t/external-database-env-vars-not-documented-external-pg-port-external-redis-env-vars/90879 "2018-06-27T15:19:44Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![zorrobyte](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zorrobyte/32/99837_2.png) [@zorrobyte](https://meta.discourse.org/u/zorrobyte)
#### Post date: [June 27, 2018, 3:19pm UTC](https://meta.discourse.org/t/external-database-env-vars-not-documented-external-pg-port-external-redis-env-vars/90879/1 "2018-06-27T15:19:44Z")

</div>

Greetings,

I can’t post in the Sysadmin category.

I can configure an external DB using:

```
DISCOURSE_DB_USERNAME
DISCOURSE_DB_PASSWORD
DISCOURSE_DB_HOST
DISCOURSE_DB_NAME

```

But I couldn’t find:

```
DISCOURSE_DB_PORT (External PostgreSQL Port)
DISCOURSE_REDIS_HOST
DISCOURSE_REDIS_USERNAME
DISCOURSE_REDIS_PASSWORD
DISCOURSE_REDIS_NAME (which database, 0,1,2,3, etc)

```

I’m an engineer at Compose/IBM and I’m attempting to setup Discourse using our production-ready, replicated databases. I’d like to run a web\_only instance with external Redis & PostgreSQL

I also couldn’t find configuration parameters for failover support:  
[https://help.compose.com/docs/postgresql-on-compose#section-for-ops-and-admins](https://help.compose.com/docs/postgresql-on-compose#section-for-ops-and-admins)

We supply two URIs “portals” for connection failover. I don’t have a ton of time to dig through the Discourse codebase and see which client driver you are using.

Lastly, we use SSL (using valid LE certs) for both Redis and PostgreSQL. Is your app configured for SSL support?

Thanks!

P.S. I’m reaching out personally, not officially from IBM/Compose. I enjoy Discourse and have been considering writing an article on how to configure Discourse using our services:  
[https://www.compose.com/articles/](https://www.compose.com/articles/)

---

<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 28, 2018, 1:45am UTC](https://meta.discourse.org/t/external-database-env-vars-not-documented-external-pg-port-external-redis-env-vars/90879/2 "2018-06-28T01:45:39Z")

</div>

You can see all of the possible global vars documented at:

> <https://github.com/discourse/discourse/blob/main/config/discourse_defaults.conf>

> You can pass in config from your environment, all the settings below are available.  
> Append DISCOURSE\_ and upper case the setting in ENV. For example:  
> to pass in db\_timeout of 200 you would use DISCOURSE\_DB\_TIMEOUT=200

---

<div class="post-metadata">

### Author: ![vsoch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vsoch/32/124967_2.png) [@vsoch](https://meta.discourse.org/u/vsoch)
#### Post date: [July 7, 2019, 9:32pm UTC](https://meta.discourse.org/t/external-database-env-vars-not-documented-external-pg-port-external-redis-env-vars/90879/3 "2019-07-07T21:32:08Z")

</div>

I’m doing this for a docker-compose application, and despite exporting the environment variable for `DISCOURSE_REDIS_HOST` (as redis) it is not honoring this variable:

```bash
name, 'name', name),\n updated_at,\n created_at,\n updated_at\nFROM facebook_user_infos\n")
discourse_1_9cc0cea436ca | rake aborted!
discourse_1_9cc0cea436ca | Redis::CannotConnectError: Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)
discourse_1_9cc0cea436ca | /usr/local/bundle/gems/redis-4.0.1/lib/redis/client.rb:344:in `rescue in establish_connection'

```

My complete code is [here](https://github.com/vsoch/discourse-compose) if you want to inspect. For some reason, the variables (that should be honored) are not. For context, I’m really wanting to help with a [plugin](https://discourse.angusmcleod.com.au/t/add-site-settings-for-vote-limits-according-to-trust-levels/1226) but the barriers to entry (setting up a basic development environment without installing everything on my host!) are huge. The only time I’ve ever gotten discourse working was using the bitnami image, which I’ve been told (somewhere else) isn’t the right way to go about it. Please help - this shouldn’t be this hard, especially to give my free time because I want to help ☹

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 8, 2019, 12:29am UTC](https://meta.discourse.org/t/external-database-env-vars-not-documented-external-pg-port-external-redis-env-vars/90879/4 "2019-07-08T00:29:29Z")

</div>

> [@vsoch](#):
>
> I’m doing this for a docker-compose application,

I’m not quite sure why you’re having that problem, but you’ll experience considerably less pain if you do it this recommended way: [Install Discourse for development using Docker](https://meta.discourse.org/t/beginners-guide-to-install-discourse-for-development-using-docker/102009)

See also, [Can Discourse ship frequent Docker images that do not need to be bootstrapped? - #6 by fbender](https://meta.discourse.org/t/can-discourse-ship-frequent-docker-images-that-do-not-need-to-be-bootstrapped/33205/6)

---

<div class="post-metadata">

### Author: ![vsoch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vsoch/32/124967_2.png) [@vsoch](https://meta.discourse.org/u/vsoch)
#### Post date: [July 8, 2019, 1:19pm UTC](https://meta.discourse.org/t/external-database-env-vars-not-documented-external-pg-port-external-redis-env-vars/90879/5 "2019-07-08T13:19:53Z")

</div>

Maybe I’m reading the code incorrectly, but the [bin/docker/boot\_dev](https://github.com/discourse/discourse/blob/master/bin/docker/boot_dev) --init script is still interacting with a database and dependencies on the host.

For the second thread, what in particular are you pointing me to look at? It has 151 posts. Thanks!

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [July 8, 2019, 3:39pm UTC](https://meta.discourse.org/t/external-database-env-vars-not-documented-external-pg-port-external-redis-env-vars/90879/6 "2019-07-08T15:39:09Z")

</div>

> [@vsoch](#):
>
> I’m doing this for a docker-compose application, and despite exporting the environment variable for `DISCOURSE_REDIS_HOST` (as redis) it is not honoring this variable:

That variable is honored in production just fine.

For development we search for a local instance by default, which works just fine if you follow one of the supported dev environments.

> **[Topics tagged dev-install](https://meta.discourse.org/tags/dev-install)**
>
> Instructions and issues with installing Discourse for development

---

<div class="post-metadata">

### Author: ![vsoch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vsoch/32/124967_2.png) [@vsoch](https://meta.discourse.org/u/vsoch)
#### Post date: [July 8, 2019, 7:08pm UTC](https://meta.discourse.org/t/external-database-env-vars-not-documented-external-pg-port-external-redis-env-vars/90879/7 "2019-07-08T19:08:32Z")

</div>

I’m running it with production as the environment variable, and it wasn’t being honored. As a workaround I changed the config with sed, and that fixed it. There are still numerous other issues I’m working on.

---

<div class="post-metadata">

### Author: ![vsoch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vsoch/32/124967_2.png) [@vsoch](https://meta.discourse.org/u/vsoch)
#### Post date: [July 8, 2019, 7:10pm UTC](https://meta.discourse.org/t/external-database-env-vars-not-documented-external-pg-port-external-redis-env-vars/90879/8 "2019-07-08T19:10:16Z")

</div>

For example, I’m starting by explicitly saying to not daemonize (to keep the container running):

```bash
bundle exec rails s --port 3000 --no-daemon --environment=production --binding 0.0.0.0

```

but it seems to decide to do it anyway! And then logically the container exits.

```plaintext
discourse_1_f60e0e3f1186 | [358] Puma starting in cluster mode...
discourse_1_f60e0e3f1186 | [358] * Version 3.12.1 (ruby 2.6.3-p62), codename: Llamas in Pajamas
discourse_1_f60e0e3f1186 | [358] * Min threads: 8, max threads: 32
discourse_1_f60e0e3f1186 | [358] * Environment: production
discourse_1_f60e0e3f1186 | [358] * Process workers: 4
discourse_1_f60e0e3f1186 | [358] * Preloading application
discourse_1_f60e0e3f1186 | [358] * Listening on tcp://0.0.0.0:3000
discourse_1_f60e0e3f1186 | [358] * Daemonizing...
docker-compose-discourse_discourse_1_f60e0e3f1186 exited with code 0

```

It’s weird that there are arguments, instructions, envars for things, but they aren’t actually honored. It’s hard to tell what I’m supposed to trust.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [July 8, 2019, 7:11pm UTC](https://meta.discourse.org/t/external-database-env-vars-not-documented-external-pg-port-external-redis-env-vars/90879/9 "2019-07-08T19:11:09Z")

</div>

> [@vsoch](#):
>
> I’m running it with production as the environment variable

Do you want a production environment or a development environment?

---

<div class="post-metadata">

### Author: ![vsoch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vsoch/32/124967_2.png) [@vsoch](https://meta.discourse.org/u/vsoch)
#### Post date: [July 8, 2019, 7:21pm UTC](https://meta.discourse.org/t/external-database-env-vars-not-documented-external-pg-port-external-redis-env-vars/90879/10 "2019-07-08T19:21:13Z")

</div>

Why can’t I run a production environment and use it for development? And what does sidekiq do? Should that be run alone to start the application? E.g., I have another container (same base) with a start command:

```plaintext
bundle exec sidekiq

```

And it depends on the main discourse container (migrating the db, precompiling static, etc.). Everything seems to work, but there is no web application.

---

<div class="post-metadata">

### Author: ![vsoch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vsoch/32/124967_2.png) [@vsoch](https://meta.discourse.org/u/vsoch)
#### Post date: [July 8, 2019, 7:25pm UTC](https://meta.discourse.org/t/external-database-env-vars-not-documented-external-pg-port-external-redis-env-vars/90879/11 "2019-07-08T19:25:27Z")

</div>

I’m happy to spend lots of (more) time on this, granted that I haven’t started anything yet, but I need a solution that doesn’t require me installing a database on my host. With containers, we shouldn’t need to do that. And again, the compose application here [GitHub - vsoch/discourse-compose: docker-compose with discourse · GitHub](https://github.com/vsoch/discourse-compose) seems to be working (no errors in any logs) yet there is no application.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 8, 2019, 7:59pm UTC](https://meta.discourse.org/t/external-database-env-vars-not-documented-external-pg-port-external-redis-env-vars/90879/12 "2019-07-08T19:59:07Z")

</div>

> [@vsoch](#):
>
> Why can’t I run a production environment and use it for development?

Because it caches and pre-compiles a bunch of stuff that basically makes doing development impossible.

> [@vsoch](#):
>
> I need a solution that doesn’t require me installing a database on my host.

The [Install Discourse for development using Docker](https://meta.discourse.org/t/beginners-guide-to-install-discourse-for-development-using-docker/102009) that I linked above does just that.

Sidekiq queues and processes jobs for later processing.

---

<div class="post-metadata">

### Author: ![vsoch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vsoch/32/124967_2.png) [@vsoch](https://meta.discourse.org/u/vsoch)
#### Post date: [July 8, 2019, 8:13pm UTC](https://meta.discourse.org/t/external-database-env-vars-not-documented-external-pg-port-external-redis-env-vars/90879/13 "2019-07-08T20:13:44Z")

</div>

What am I missing? The command for --init is run on the host:

> <https://github.com/discourse/discourse/blob/main/bin/docker/boot_dev#L70>

---

<div class="post-metadata">

### Author: ![vsoch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vsoch/32/124967_2.png) [@vsoch](https://meta.discourse.org/u/vsoch)
#### Post date: [July 8, 2019, 8:17pm UTC](https://meta.discourse.org/t/external-database-env-vars-not-documented-external-pg-port-external-redis-env-vars/90879/14 "2019-07-08T20:17:43Z")

</div>

> [@pfaffman](#):
>
> Because it caches and pre-compiles a bunch of stuff that basically makes doing development impossible.

Fair enough, but let’s say that I’m doing the precompiling anyway (it does take a while!) and I want to start the server. Why does it not work?

---

<div class="post-metadata">

### Author: ![vsoch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vsoch/32/124967_2.png) [@vsoch](https://meta.discourse.org/u/vsoch)
#### Post date: [July 8, 2019, 9:47pm UTC](https://meta.discourse.org/t/external-database-env-vars-not-documented-external-pg-port-external-redis-env-vars/90879/15 "2019-07-08T21:47:41Z")

</div>

Okay I gave in and ran the --init command. I can confirm the container is running:

```plaintext
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d2254e1374f5 discourse/discourse_dev:release "/sbin/boot" 24 minutes ago Up 24 minutes 0.0.0.0:1080->1080/tcp, 0.0.0.0:3000->3000/tcp, 0.0.0.0:9292->9292/tcp, 0.0.0.0:9405->9405/tcp discourse_dev

```

But I’m not seeing any record of it at any port. I’ve tried two browsers, localhost, 127.0.0.1, and 0.0.0.0 and there is no web application. The error is `ERR_CONNECTION_RESET`. I don’t see anything in iptables that would block this:

```plaintext
Chain DOCKER (3 references)
target prot opt source destination         
ACCEPT tcp -- anywhere 172.17.0.2 tcp dpt:9405
ACCEPT tcp -- anywhere 172.17.0.2 tcp dpt:9292
ACCEPT tcp -- anywhere 172.17.0.2 tcp dpt:3000
ACCEPT tcp -- anywhere 172.17.0.2 tcp dpt:socks

```

* * *

Update July 10, 2019

Thanks for everyone’s help - the issue was needing to issue that “unicorn” command, and I now have everything working. I also had to run `rake admin:create` in the start command, otherwise it wants an email confirmation (full repo [here](https://github.com/vsoch/discourse-compose/)). The `discourse_dev` works too.
