# Multisite configuration with Docker

**URL:** https://meta.discourse.org/t/multisite-configuration-with-docker/14084
**Category:** Self-Hosting
**Tags:** docker, explanation, advanced-setup, multisite
**Created:** [March 25, 2014, 5:21am UTC](https://meta.discourse.org/t/multisite-configuration-with-docker/14084 "2014-03-25T05:21:03Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [March 25, 2014, 5:21am UTC](https://meta.discourse.org/t/multisite-configuration-with-docker/14084/1 "2014-03-25T05:21:03Z")

</div>

> ⚠ 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 to learn about them.

Discourse templates use [pups](https://github.com/discourse/pups); its rules are simple and powerful.

Each rule you run may define a hook:

```plaintext
run:
  exec:
    cd: some/path
    hook: my_hook
    cmd:
      - echo 1

```

Later on in your container you can _insert_ rules before or after a hook:

```plaintext
hooks:
  before_my_hook:
    - exec: echo "I ran before"
  after_my_hook:
     - exec: echo "I ran after"

```

So in the example above you will see output like the following:

> I ran before  
> 1  
> I ran after

You can read through the templates in `/var/discourse/templates` to see what hooks you have available.

### Amend your standalone container to provision the second site tenant

Replace the **entire** hooks section with:

```plaintext
hooks:
  after_postgres:
     - exec: sudo -u postgres createdb b_discourse || exit 0
     - exec:
          stdin: |
            grant all privileges on database b_discourse to discourse;
          cmd: sudo -u postgres psql b_discourse
          raise_on_fail: false

     - exec: /bin/bash -c 'sudo -u postgres psql b_discourse <<< "alter schema public owner to discourse;"'
     - exec: /bin/bash -c 'sudo -u postgres psql b_discourse <<< "create extension if not exists hstore;"'
     - exec: /bin/bash -c 'sudo -u postgres psql b_discourse <<< "create extension if not exists pg_trgm;"'

  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git
  before_bundle_exec:
    - file:
        path: $home/config/multisite.yml
        contents: |
         secondsite:
           adapter: postgresql
           database: b_discourse
           pool: 25
           timeout: 5000
           host_names:
             - b.discourse.example.com

  after_bundle_exec:
    - exec: cd /var/www/discourse && sudo -H -E -u discourse bundle exec rake multisite:migrate

```

There are 4 hooks in play:

1. `after_postgres` ensures that after postgres is installed an additional db called `b_discourse` is created with the appropriate permissions and required extensions.

2. `after_code` ensures `docker_manager` is cloned into the plugins directory.

3. `before_bundle_exec` ensures that the `multisite.yml` file is in place (which defines where to find the databases).

4. `after_bundle_exec` runs the custom db migration task `rake multisite:migrate` — this ensures all the dbs are up to date.

### Note on configuration

The above sample can be split into data container / app container if needed. Just run the `after_postgres` hook in the **data** container and the rest in **web** container.

The above sample can be extended to provision even more DBs. To do so, provision more DBs by duplicating the create db etc calls, and make sure you add additional sites in `multisite.yml`.

Make **sure** you amend the `host_names` node in `multisite.yml` to match the actual host name you wish to host.

Also, if you plan to run HTTPS, you will need a proxy in front of the site to handle it as the built in letsencrypt functionality will not work in a multisite scenario.

> Last edited by @sam 2026-02-02T00:52:28Z
> 
> > **Check document**
> >
> > Perform check on document:

---

<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: [March 18, 2026, 4:04am UTC](https://meta.discourse.org/t/multisite-configuration-with-docker/14084/176 "2026-03-18T04:04:41Z")

</div>

12 posts were split to a new topic: [Various multisite installation questions](https://meta.discourse.org/t/various-multisite-installation-questions/398693)
