Multisite configuration with Docker

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

Discourse templates use pups; its rules are simple and powerful.

Each rule you run may define a hook:

    cd: some/path
    hook: my_hook
      - echo 1

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

    - exec: echo "I ran before"
     - exec: echo "I ran after"

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

I ran before
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:

     - 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;"'

    - exec:
        cd: $home/plugins
          - mkdir -p plugins
          - git clone
    - file:
        path: $home/config/multisite.yml
        contents: |
           adapter: postgresql
           database: b_discourse
           pool: 25
           timeout: 5000
           db_id: 2

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

There are 3 hooks in play:

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

  2. before_bundle_exec, ensures docker_manager is in place and that the multisite.yml file is in place (which defines where to find the databases)

  3. 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.

How does multisite.yml look?
Multiple Forums in a Single Installation
How to create 1000 subcategories in a scalable way?
Multiple Discourses, multiple containers, one server
Pros and cons of multiple standalone containers vs one for multiple Discourse installs?
Success - New Multisite Install on Dedicated server using ServerPilot, Nginx and Apache
Multisite Installation
Will I need to start over with multisite configuration from standalone version?
Starting a second Discourse forum on the same VPS
Pros and cons of a multisite installation
Installation wizard not appearing in multisite installs
Multiple Discourse Installs - Single Server
How do you set up multiple discourse forums on the same server?
Multisite installation with seperated smtp emails
Sandbox and test discourse on host?
Disabling/restricting user search
Second discourse instance on the same server
Remove sites from multisite config with Docker
Discourse multisite installation help with digitalocean
How to move from standalone container to separate web and data containers
Micro Forums: how many could I create?
Need proper documentation for multisite discourse with docker
Discourse for 3 different Countrys
How to setup host mapping on a multi-site discourse instance
Multisite viability - 2 read-only and 1 active
Install Discourse on Plesk / Ubuntu 14 without Docker
Totally Walled-Off Groups
Recover to one site from multisite
Can I log into multiple instances of discourse simultaneously?
Multiple discourse instances in a single server
Three sites in one setup
Adding an instance to multisite without rebuilding the container
I want to host hundreds of instances of Discourse
How to set redis DB ID in Docker container?
Running other websites on the same machine as Discourse
How can I host more than 1 Discourse forum on 1 VPS?
Multiple discourse installation on single droplet
Running other websites on the same machine as Discourse
Setting up Let’s Encrypt with Multiple Domains
Setting up Let’s Encrypt with Multiple Domains
Docker image update: Redis 6 and 25% smaller image size
Multisite Configuration with Let's Encrypt and no reverse proxy
Publishing multisite
How could I install another discourse on same server (docker)?
All users are visible in @mentions autocomplete list
Multiple container setup problems
Feature proposal: Customizations based on primary group membership, a.k.a. tenancy 'lite'
Stable branch assets won't compile
Stable branch assets won't compile
Pull request for Wikis?
PAID Require Discourse expert for extreme customization
Multitenat Dockerize Discourse
Add path to cookie
App.yml shared volumes for a two website setup
Contabo experience with Plesk, Webmin or other server-admin setup?
How to move from standalone container to separate web and data containers
Not receiving activation email for admin on multisite installation
Using a launcher built docker image in docker-compose
How to move from standalone container to separate web and data containers
Two standalone instances on one server?
Best approach for test and production instance of discourse
Multisite Config
Are there other workarounds to not having category moderation such as multiple instances of the board?
WP SSO + Discourse Multisite
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column categories.search_priority does not exist
Multisite installation ... in subdirectories?
Multiple discourse instances in a single server
How do I set category tracking level defaults historically
Integration with .NET MVC application for a SaaS platform
Multisite for small collection of sites for a family?
Need help with multisite configuration
Multiple communities on discourse?
Hosting Plan Suggestion for 500 Concurrent Online Users
Avatar, Site Logos, and Cert Errors
Secure cookie configuration
How to move from standalone container to separate web and data containers
Can I have two domains pointing towards the same IP address without redirect?
How to move from standalone container to separate web and data containers
Help me setup many websites on one VPS
How can Admin login while Read-only mode is enabled on multisite?
Installing on Kubernetes
How might we better structure #howto?

I’ve verified this guide is correct and made some copy edits for readability and structure.


I intend to update this guide with instructions to use Let’s Encrypt without an external reverse proxy as suggested here.

I created a separate topic: Multisite Configuration with Let's Encrypt and no reverse proxy

I’m not sure if we should keep both, but I think so. This guide does have some information about hooks that I didn’t really understand until very recently.


I would like to understand where would static uploaded files, like images, be located? All sites would share the same folder? How/would it be possible to customize?

It sounds like you don’t understand how Discourse works? You don’t customize it by uploading files (except through the UX in various ways).

Uploads go somewhere like


Backups like


I didn’t explain myself well, sorry. But anyway you solved my doubt. I am about to migrate to multisite to run two discourses without multiplying containers/resources, and I wasn’t aware that inside /var/discourse/shared/web_only , there is / would be folders with SITE_NAME . That’s perfect.


Well, after having everything set up correctly, I stumped upon the limitation of Allow update smtp settings in admin panel

Currently that’s still valid, I guess? So for my use case I will probable go the route of 2 web containers and 1 data container

1 Like

Yes. Multisite has a single smtp settings, though you can set notification email for each site.