# 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:** [5월 29, 2015, 2:12오후 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:** 1
**Showing post:** 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: [5월 29, 2015, 2:12오후 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)

---

_[View the full topic](https://meta.discourse.org/t/move-from-standalone-container-to-separate-web-and-data-containers/29413)._
