# Move from standalone container to separate web and data containers

**URL:** https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413
**Category:** Sysadmins
**Tags:** docker, how-to, advanced-setup, two-container
**Created:** [May 29, 2015, 2:12pm UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413 "2015-05-29T14:12:22Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![5minpause](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/5minpause/32/116074_2.png) [@5minpause](https://meta.discourse.org/u/5minpause)
#### Post date: [May 29, 2015, 2:12pm UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/1 "2015-05-29T14:12:22Z")

</div>

> ⚠ This is an advanced setup. Don’t follow this unless you are experienced with Linux server administration and Docker. You also need to pay close attention to commits to discourse\_docker to make sure you notice if there’s a version bump for postgres or redis.

### Converting your Current Setup

I managed to migrate to two containers. If anyone else needs instructions, this is how it worked for me.

The process includes backup, setting up separate web and data containers and restore data.

1. Backup your discourse instance and download backup. You can follow the [simple guide](https://meta.discourse.org/t/move-your-discourse-instance-to-a-different-server/15721) or [backup and restore later manually](https://meta.discourse.org/t/advanced-manual-method-of-manually-creating-and-restoring-discourse-backups/18273).

2. Stop current standalone container  
`./launcher stop app`

3. copy `web_only.yml` and `data.yml` from `samples/` to `containers/` rename them to whatever you’d like, e.g. `web_rocks.yml` and `data2.yml`.

4. if you rename them, please pay attention to the entries `volumes:` in `data.yml` and `web_only.yml`  
If you renamed `web_only.yml` to `web_rocks.yml` you need to modify the entry in `Web_rocks.yml` like this:

```plaintext
volumes:
  - volume:
      host: /var/discourse/shared/web_rocks
      guest: /shared
  - volume:
      host: /var/discourse/shared/web_rocks/log/var-log
      guest: /var/log

```

Accordingly, do the similar editing in `data.yml` also.

### Setting up data container

Start with `data.yml` and set a password for the database. Then:

- come to the container’s root folder `/var/discourse`
- run `./launcher bootstrap data2` (data2 or whatever new name you gave it)
- run `./launcher start data2` (using new name again)
- if everything goes smoothly you can connect to the container via: `./launcher enter data2` (again using the new name)
- Exit the container by `exit`.

### Setting up web container

Let’s modify `web_only.yml`.

Firstly, change the template and expose ports as your `app.yml` does.

Secondly, make sure you are linking to the right data container. If you renamed the data.yml to ‘something\_else’ put it in for ‘name’.

```
# Use 'links' key to link containers together, aka use Docker --link flag.
links:
  - link:
      name: data
      alias: data

```

Although we don’t want to expose ssh or any other ports anymore, you’d still need to expose 80 and 443 port for web access. This depends on whether you have a nginx running in the front and how you connect container with it.

Somewhere in there you’ll find this block:

```plaintext
  DISCOURSE_DB_USERNAME: discourse
  DISCOURSE_DB_PASSWORD: mypassword
  DISCOURSE_DB_HOST: data
  DISCOURSE_REDIS_HOST: data

```

- Enter the password you set inside the data container.
- Enter the data container’s alias you just wrote down. For `DB_HOST` and for `REDIS_HOST`. It has to match the links block we mentioned.
- You probably didn’t change the `DB_USERNAME`.

You’ll find the values for `DISCOURSE_DEVELOPER_EMAILS` and `DISCOURSE_HOSTNAME` and many more. You already have these values in your `app.yml`. Copy them from there.

In the hooks section remember to set any additional plugins you already use inside app.yml

Now you should be ready to bootstrap it:  
`./launcher bootstrap web_only` (again with your new/own name)

Once bootstrapped, you can start `web_only` (use your new name):  
`./launcher start web_only`

When Discourse is ready, login and restore your site.

After this, everything worked again for me and my discourse installation was running again, but now in two separate containers.

### How to update when using separate web and data containers

If you do not care about the few minutes of downtime – or when data needs to be upgraded. Changes to postgres and redis are infrequent, and leaving the data container running is what makes it possible to build a new web\_only container while the old one runs.

```plaintext
./launcher stop web_only && ./launcher rebuild data && ./launcher rebuild web_only

```

That works for a minor upgrade to Postgres and/or a redis upgrade.

If you care about every minute of downtime **and** data does not need to be upgraded (which is most of the time):

##### upgrade only `web_only`:

```plaintext
./launcher bootstrap web_only && ./launcher destroy web_only && ./launcher start web_only

```

It’s enough to rebuild `web_only` and skip `data` except when there is an upgrade to postgres or redis. Those happen on the order of once a year and you’ll see an announcement like [PostgreSQL 15 update](https://meta.discourse.org/t/postgresql-15-update/349515) when it happens, though upgrades to redis and minor postgres updates are not as obviously announced.

Rebuilding data requires downtime (for the same reason that the single-container version does–you can’t upgrade postgres while another process is accessing the same database files. Also, when you build a new data container, you must destroy and start the web\_only container because it will try to connect to the old container.

You do not often need to rebuild the data container (which is why this method saves downtime). You need to pay attention to when there is an upgrade in postgres or redis; the front end won’t know; this is an advanced setup that requires more attention than a single container.

#### Managing a two-container installation

@pfaffman will one day create a topic about this, but until then, there is this: [Managing a Two-Container Installation - Documentation - Literate Computing Support](https://support.literatecomputing.com/t/managing-a-two-container-installation/310)

---

<div class="post-metadata">

### Author: ![downey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/downey/32/166878_2.png) [@downey](https://meta.discourse.org/u/downey)
#### Post date: [March 3, 2016, 2:33am UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/2 "2016-03-03T02:33:11Z")

</div>

This … didn’t work as expected.

(The instructions are a bit off but I followed the update at [https://meta.discourse.org/t/faster-rebuilds/40341/4.](https://meta.discourse.org/t/faster-rebuilds/40341/4.))

Should the new 2-container installation present an empty/fresh site? I was assuming it would copy all of my settings & data from my `app` container, but it was brand new. ☹

**Edit:** I did a restore from a backup made just before the process, and it seemed to restore everything. So probably this just needs to be made clear. 🙂

---

<div class="post-metadata">

### Author: ![fantasticfears](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fantasticfears/32/119608_2.png) [@fantasticfears](https://meta.discourse.org/u/fantasticfears)
#### Post date: [March 3, 2016, 4:31pm UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/3 "2016-03-03T16:31:56Z")

</div>

I updated the guide. Hope it reflects your process.

---

<div class="post-metadata">

### Author: ![downey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/downey/32/166878_2.png) [@downey](https://meta.discourse.org/u/downey)
#### Post date: [May 4, 2016, 7:36pm UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/4 "2016-05-04T19:36:31Z")

</div>

When someone like @sam puts out instructions to rebuild the “app” container for fixes like this one, is it safe to assume it’s generally going to be in the `web_only` container?

> [@ImageMagick CVE-2016–3714](https://meta.discourse.org/t/imagemagick-cve-2016-3714/43624/5):
>
> Fixed per: [https://github.com/discourse/discourse\_docker/commit/d47aa69bb72dea153b6901866bb66afe2cca6915](https://github.com/discourse/discourse_docker/commit/d47aa69bb72dea153b6901866bb66afe2cca6915) I will also rebuild the entire image next week when Image Magick do a new point release. To take advantage of the fix: cd /var/discourse ./launcher rebuild app

---

<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: [May 5, 2016, 12:04am UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/5 "2016-05-05T00:04:21Z")

</div>

Yes, anything that mixes in the template I hacked get this.

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [February 13, 2017, 2:53pm UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/6 "2017-02-13T14:53:04Z")

</div>

Sorry for the bump on this old conversation, but I had a related issue.

While doing server upgrades that included docker daemon upgrades, docker restarted, but when it did restart, it also restarted the standalone `app` container, which brought the site back to what it was pre-transitioning to separate containers. After panicking, I stopped the app container, and then started `web_only` again, and site is back to normal.

But how can I fix this permanently? I tried moving the app.yml file away from the `containers` folder, but the `app` docker container still restarts. Should I run `./launcher destroy app` ?

P.S. I am mentioning this here, because I did successfully move from a standalone `app` container to separate data/web\_only containers as described here.

---

<div class="post-metadata">

### Author: ![tophee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tophee/32/73406_2.png) [@tophee](https://meta.discourse.org/u/tophee)
#### Post date: [July 4, 2017, 8:02am UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/7 "2017-07-04T08:02:20Z")

</div>

Excuse my ignorance but could someone explain to me why this is not the default setup (or an optional setup) in the 30 min install guide?

I understand that using two containers [minimizes the downtime during rebuilds](https://meta.discourse.org/t/faster-rebuilds/40341/13) and since nobody likes downtime, it seems like everyone would want two containers…

In other words: what’s the catch?

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [July 4, 2017, 10:53am UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/8 "2017-07-04T10:53:29Z")

</div>

> [@tophee](#):
>
> In other words: what’s the catch?

It’s more complicated to set up? More has to be done during setup? More potential points of failure? Harder to debug if you don’t understand Docker?

---

<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 4, 2017, 5:32pm UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/9 "2017-07-04T17:32:27Z")

</div>

> [@tophee](#):
>
> In other words: what’s the catch?

For people like you and me, there is none.

When the 30 minute install was conceived, it involved editing `app.yml` with a tool like nano (I’m an Emacs user and even I prefer `vi` to nano). Having people edit copy and edit _two_ files and bootstrap and start both of them in the right order is on the order of 10 times more complicated. Now that `./discourse-setup` is how most people configure Discourse, the setup part could be exactly the same for a two-container setup. I’ve looked in to doing just that & it wouldn’t be very hard.

But even still, with two containers, there would then be a bunch of problems with the data container wasn’t running and then no one would say which way their site was configured and that would be a lot more complicated to help out. Most of the time the web-based upgrade works just fine, and so unless you’re changing your plugin config, there’s not _that_ much of a win for the two-container setup.

I think soon that I’ll start offering a two-container setup along side of my [$99 install](https://www.literatecomputing.com/product/discourse-install/), but I’ve not gotten around to it.

---

<div class="post-metadata">

### Author: ![tophee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tophee/32/73406_2.png) [@tophee](https://meta.discourse.org/u/tophee)
#### Post date: [July 4, 2017, 6:01pm UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/10 "2017-07-04T18:01:39Z")

</div>

> [@pfaffman](#):
>
> For people like you and me, there is none

So is everyone here just pretending that they’re running one container but privately they’re running two?

Well, I guess, maybe even for “people like you and me” it is more convenient with one container, given that you don’t change plugins so often.

On the other hand, on standard troubleshooting advice that keeps coming up is obviously “disable all apps and re-enable them onr by one” and unless you do that by just disabling them under settings, this will give you plenty of downtime with one container…

And when I see that people are talking about 10,000 visits per day, that is quite a few annoyed users, even for half an hour downtime.

Anyway, thanks for explaining. And, yes, you should offer the 2-container install, if only to make it better known 😉

---

<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 4, 2017, 6:16pm UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/11 "2017-07-04T18:16:03Z")

</div>

> [@tophee](#):
>
> So is everyone here just pretending that they’re running one container but privately they’re running two?

No. Usually if someone posts a problem and they’re running multiple containers, they’ll mention that (probably because it’s a problem specifically with multiple containers), but mostly, if you know how to have multiple containers, it won’t make any difference that you do.

FWIW, it took me nearly 2 years to (bother to) figure it out. And six months of that time I was earning all of my income from Discourse consulting (not to say that the income I earned was a living all of that time).

I’d guess that the vast majority of people running Discourse have a single container. I’d guess that the vast majority of people\* who earn some of their income from managing or hosting it\* and/or would identify as a “system administrator” run two.

---

<div class="post-metadata">

### Author: ![net\_deamon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/net_deamon/32/70126_2.png) [@net\_deamon](https://meta.discourse.org/u/net_deamon)
#### Post date: [July 10, 2017, 10:17am UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/12 "2017-07-10T10:17:25Z")

</div>

> [@tophee](#):
>
> In other words: what’s the catch?

It is not that hard too. You have `app.yml` file which contains both the properties of datasource and web related(which port discourse should run eg 9000, or the plugins config and the custom commands)

So you just divide the `app.yml` into `data.yml` and `web.yml`.  
Data.yml will contain the datasources part from app.yml  
While the web.yml will contain rest of config.

I usually use nginx webserver infront of discourse.  
So I can rebuild another web contianer at say 9001, and reverse proxy to it from nginx.  
Then I safely stop the previous web container running at 9000.  
This swapping is done in few seconds… So there is no downtime.

---

<div class="post-metadata">

### Author: ![Berto](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/berto/32/77084_2.png) [@Berto](https://meta.discourse.org/u/Berto)
#### Post date: [September 5, 2017, 1:32pm UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/13 "2017-09-05T13:32:09Z")

</div>

Could use some help here:

> [@5minpause](#):
>
> Start with data.yml and set a password for the database. Then:

This is confusing. It states to do a step (set a password) but doesn’t state _how_ to do that aforementioned step… and immediately says “then” do some other stuff. Are we missing instructions on setting this password here?

So I didn’t change any password because I don’t know how or what OP is talking about, but did run `./launcher boostrap data` and got the following response:

```plaintext
[...bootstrap command running...]
Successfully bootstrapped, to startup use ./launcher start data

prompt$ ./launcher enter data
Error: No such container: data

```

Note that I didn’t rename anything, only copied the files. I simply have `data.yml` and `web_only.yml` in my `/var/discourse/containers` directory.

Thanks!

---

<div class="post-metadata">

### Author: ![5minpause](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/5minpause/32/116074_2.png) [@5minpause](https://meta.discourse.org/u/5minpause)
#### Post date: [September 5, 2017, 1:47pm UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/14 "2017-09-05T13:47:58Z")

</div>

I wrote this “guide” in May 2015. I do not use Discourse any more (stopped soon after). I do not know if any of these instructions still work or how things are done nowadays.

---

<div class="post-metadata">

### Author: ![Berto](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/berto/32/77084_2.png) [@Berto](https://meta.discourse.org/u/Berto)
#### Post date: [September 5, 2017, 2:18pm UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/15 "2017-09-05T14:18:25Z")

</div>

Thanks, people are still linking to it, going to just hire some help. Cheers!

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [September 5, 2017, 9:33pm UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/17 "2017-09-05T21:33:04Z")

</div>

Thanks for getting it started, we will take it from here!

---

<div class="post-metadata">

### Author: ![TheBestPessimist](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thebestpessimist/32/247704_2.png) [@TheBestPessimist](https://meta.discourse.org/u/TheBestPessimist)
#### Post date: [May 28, 2018, 6:38pm UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/18 "2018-05-28T18:38:16Z")

</div>

Is this still the good tutorial?

Or should follow

> [@Configure Discourse to use a separate PostgreSQL server](https://meta.discourse.org/t/running-discourse-with-a-separate-postgresql-server/46375):
>
> Let’s say you’re using AWS RDS, or an existing PostgreSQL server managed elsewhere. It’s fairly straightforward to get Discourse to use such a setup, without needing to grant superuser privileges to anything that Discourse itself runs. Here’s how. Prerequisites Discourse requires PostgreSQL’s major version to [match what we ship with in our docker images](https://github.com/discourse/discourse_docker/blob/main/image/base/Dockerfile#L37); if you try to run on a newer or older version, it might work, but we don’t guarantee it, and if something breaks in the future, you get to …

or

> [@Multisite configuration with Docker](https://meta.discourse.org/t/multisite-configuration-with-docker/14084):
>
> warning While multisite is supported in the Discourse application, this is an advanced sysadmin setup. If you don’t know what you’re doing, do not set up multisite. The Discourse team is unable to provide multisite configuration support. If you wish to host multiple domains on a singled Docker setup, you’ll need a multisite configuration. Here are the basic building blocks for one. Understand hooks Multisite is a fairly advanced topic. Before attempting a multisite build, spend some time…

Right now both of those tutorials still leave me with questions :-/.

---

<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: [May 28, 2018, 6:44pm UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/19 "2018-05-28T18:44:18Z")

</div>

The 3 tutorials apply to 3 different situations, so pick the one that applies to what you want.

[Configure Discourse to use a separate PostgreSQL server](https://meta.discourse.org/t/running-discourse-with-a-separate-postgresql-server/46375) is for when you have an external PostgreSQL running somewhere else, like AWS RDS.

[Multisite configuration with Docker](https://meta.discourse.org/t/multisite-configuration-with-docker/14084) is about running multiple Discourse instances inside the same container.

And this topic is about using different containers for data and web.

The three guides are for advanced users, and we recommend sticking to defaults for people who aren’t familiar with Discourse, containers and the whole sysadmin lingo.

---

<div class="post-metadata">

### Author: ![TheBestPessimist](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thebestpessimist/32/247704_2.png) [@TheBestPessimist](https://meta.discourse.org/u/TheBestPessimist)
#### Post date: [May 28, 2018, 6:47pm UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/20 "2018-05-28T18:47:23Z")

</div>

well, what i want is to be able to host 3 discourse forums on my own VM.

From that i understand that i need to

1. Separate the data and web containers (this also brings speedup when rebuilding the app)
2. Configure 2 other discourse instances (somehow?) for my 2 other forums.

So this is why i don’t know exactly how to approach this situation.

---

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [May 29, 2018, 8:30am UTC](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413/21 "2018-05-29T08:30:06Z")

</div>

> [@TheBestPessimist](#):
>
> Separate the data and web containers (this also brings speedup when rebuilding the app)

You may want to do that (mainly to reduce rebuild times), but this is not required, and doesn’t really have anything to do with running multiple sites.

To run three sites, you can either bootstrap them separately (which is rather easy, but triples resource requirements), or use these instructions for setting up multisite:

> [@Multisite configuration with Docker](https://meta.discourse.org/t/multisite-configuration-with-docker/14084):
>
> warning While multisite is supported in the Discourse application, this is an advanced sysadmin setup. If you don’t know what you’re doing, do not set up multisite. The Discourse team is unable to provide multisite configuration support. If you wish to host multiple domains on a singled Docker setup, you’ll need a multisite configuration. Here are the basic building blocks for one. Understand hooks Multisite is a fairly advanced topic. Before attempting a multisite build, spend some time…

I’m running a setup like this (i.e. multisite, but without separating data and web containers or any other fanciness), and this works fine, but setup is indeed a bit tricky.

[Next page](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413.md?page=2)
