Multisite-Konfiguration mit 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:

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:

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:

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
           db_id: 2
           host_names:
             - b.discourse.example.com

  after_bundle_exec:
    - 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.

Last edited by @mcwumbly 2026-01-03T15:38:08Z

Check documentPerform check on document:
68 „Gefällt mir“
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
Multiple Discourse Installs - Single Server
Pros and cons of a multisite installation
Installation wizard not appearing in multisite installs
Disabling/restricting user search
How do you set up multiple discourse forums on the same server?
Sandbox and test discourse on host?
Multisite installation with seperated smtp emails
Help me setup many websites on one VPS
Discourse for 3 different Countrys
Micro Forums: how many could I create?
Remove sites from multisite config with Docker
Second discourse instance on the same server
Discourse multisite installation help with digitalocean
Need proper documentation for multisite discourse with docker
Not receiving activation email for admin on multisite installation
Can I log into multiple instances of discourse simultaneously?
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
Three sites in one setup
I want to host hundreds of instances of Discourse
Recover to one site from multisite
Publishing multisite
Multisite Config
Multiple communities on discourse?
Adding an instance to multisite without rebuilding the container
Is it possible to totally hide members
How could I install another discourse on same server (docker)?
Need help with multisite configuration
Multitenat Dockerize Discourse
Installing on Kubernetes
How might we better structure #howto?
How to set redis DB ID in Docker container?
Discourse instance stops running in every midnight
How can I host more than 1 Discourse forum on 1 VPS?
Multiple discourse installation on single droplet
Multiple discourse instances in a single server
Setup Multisite Configuration with Let's Encrypt and no Reverse Proxy
Docker image update: Redis 6 and 25% smaller image size
Setup Multisite Configuration with Let's Encrypt and no Reverse Proxy
Add path to cookie
Multisite installation ... in subdirectories?
Pups::ExecError
Web-only - do I need a separate image for each container?
PAID Require Discourse expert for extreme customization
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column categories.search_priority does not exist
Pull request for Wikis?
WP SSO + Discourse Multisite
One server for 2 Discourse communities?
Are there other workarounds to not having category moderation such as multiple instances of the board?
All users are visible in @mentions autocomplete list
Migrate from VPS to a Dedicated
Best approach for test and production instance of discourse
Discourse Multisite – Nginx (Inside Docker) Only Serving Default Site
One server for 2 Discourse communities?
Two Discourse communities on the same VPS
How can I use different setting value for subdomain?
Will This Configuration Successfully Create a Second Discourse Instance (with Proxy)?
Pups::ExecError
Use CloudPanel to manage multiple sites with Discourse
Two standalone instances on one server?
Using a launcher built docker image in docker-compose
Stable branch assets won't compile
Does discourse hosting use docker for all customer instances?
Tips for setting up a multi-subdomain Discourse instance with shared SSO?
Stable branch assets won't compile
Feature proposal: Customizations based on primary group membership, a.k.a. tenancy 'lite'
How can Admin login while Read-only mode is enabled on multisite?
Move from standalone container to separate web and data containers
Move from standalone container to separate web and data containers
Move from standalone container to separate web and data containers
Guidance on multi-site setup
Running multiple things on the same sever as my Pi (where Discourse is hosted)?
Contabo experience with Plesk, Webmin or other server-admin setup?
Multisite for small collection of sites for a family?
Integration with .NET MVC application for a SaaS platform
Hosting Plan Suggestion for 500 Concurrent Online Users
App.yml shared volumes for a two website setup
Avatar, Site Logos, and Cert Errors
Database access issues after upgrade v3.5.2 -> v3.6.0.beta2
How extensible can I make my installation in terms of sub domains and restricting membership to them?
Move from standalone container to separate web and data containers
Can I have two domains pointing towards the same IP address without redirect?
Move from standalone container to separate web and data containers
Multiple container setup problems

Ich habe mich gefragt, was der Wert db_id: 2 in der oben vorgeschlagenen Konfiguration bewirkt?

Außerdem, wie ist das Vorgehen, um eine neue Website zum bestehenden Multisite-Setup hinzuzufügen? Ist es nur:

  • YAML aktualisieren
  • ./launcher bootstrap multisite [1]
  • ./launcher start multisite

Ich habe mich gefragt, ob es eine Möglichkeit gibt, alle anderen bestehenden Websites nicht zu beeinträchtigen, indem man einen vollständigen Bootstrap oder Rebuild durchführt und irgendwie nur die zusätzliche benötigte Datenbank hinzufügt?


  1. Ich habe zuerst ./launcher rebuild multisite versucht, aber das scheint fehlzuschlagen. ↩︎

Ich glaube, die DB-ID wird nicht mehr benötigt.

Sie können einfach die Multisite-Datei mit der neuen Website bearbeiten und dann

sv restart unicorn

ausführen und dann die Datenbank migrieren.

1 „Gefällt mir“

Du bist ein Lebensretter!

Mir fehlte dieser Befehl zum Neustarten (ich habe auch sv reload unicorn versucht, aber irgendwie reichte das nicht aus).

Gibt es in Bezug auf die Erstellung der Datenbank bereits eine Möglichkeit, dies automatisch zu tun? Es wäre schön, rake db:create[mynewdbname] zu haben. Ansonsten kann ich ein kurzes Shell-Skript schreiben.

Im Moment erstelle ich manuell (Datenbank erstellen und Berechtigungen festlegen) und führe dann RAILS_DB=newdb rake db:migrate aus, um sie zu füllen.

Und nur um zu prüfen, ob ich etwas Dummes mache:

  • Im Moment bearbeite ich die Multisite-Datei innerhalb von Docker (/var/www/discourse/config/multisite.yml)
  • Erstelle die DB manuell
  • Führe rake db:migrate aus
  • sv restart unicorn
  • Ich muss dann auch die YAML-Datei außerhalb von Docker bearbeiten, damit die Multisite-Konfiguration bei zukünftigen Rebuilds oder Upgrades synchron ist.

Bin ich albern, wenn ich die Multisite-Konfiguration an 2 verschiedenen Stellen bearbeite, obwohl es bereits eine Möglichkeit gibt, sie an einer Stelle zu bearbeiten und die Änderungen durchzudrücken?

1 „Gefällt mir“

Ist es möglich, diese Dokumentation etwas aufzuräumen und mehr Anleitungen darin zu geben? Ich bin erstens extrem neu bei Docker und obwohl ich Linux-Server-Erfahrung habe, bin ich kein Profi darin. Ich bin ein Old-Schooler, liebe meine Cron-Jobs und Shell-Skripte und Sie wissen, seltsame Dinge wie diese mit Apache Multi-Site usw. Aber das ist etwas komplexer und verwendet eine andere Programmiersprache als ich es gewohnt bin. Vielleicht sogar ein Demovideo in irgendeiner Form? Es wäre schön, wenn Discourse einfach Multi-Site-fähig gemacht würde und man dann nur ein paar Dateien bearbeiten müsste usw.

2 „Gefällt mir“

Fügen Sie einfach diese Textstrophe ein und bearbeiten Sie sie nach Bedarf.

Sie benötigen dann entweder einen Reverse-Proxy oder müssen Let’s Encrypt mit mehreren Domains / Weiterleitungen einrichten, um Zertifikate für alle Domains zu erhalten.

Siehe auch Multisite-Konfiguration mit Let’s Encrypt und ohne Reverse Proxy einrichten. Aber diese muss aktualisiert werden, um eine weitere erforderliche Zeile zu enthalten, die Sie aus dem vorherigen Link erhalten können. Ich wollte sie schon aktualisieren, habe es aber noch nicht geschafft.

1 „Gefällt mir“

Wenn ich Multisite betreibe, wohin sollte ich meine Domain leiten? Zur gleichen IP wie der Server (der ein anderes Forum hostet)?

Ja, leiten Sie alle Domains auf dieselbe Server-IP weiter.
Richten Sie einen Reverse-Proxy mit Nginx oder Caddy-Server ein.
Caddy ist am besten, da es kostenlose automatische SSL-Zertifikate für alle Ihre Domains bietet.

1 „Gefällt mir“