Configuración multisite con 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 Me gusta
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
Multisite installation with seperated smtp emails
Sandbox and test discourse on host?
Disabling/restricting user search
How do you set up multiple discourse forums on the same server?
Help me setup many websites on one VPS
Remove sites from multisite config with Docker
Micro Forums: how many could I create?
Discourse for 3 different Countrys
Discourse multisite installation help with digitalocean
Second discourse instance on the same server
Need proper documentation for multisite discourse with docker
Publishing multisite
How to setup host mapping on a multi-site discourse instance
Multisite viability - 2 read-only and 1 active
Totally Walled-Off Groups
How could I install another discourse on same server (docker)?
Multisite Config
Recover to one site from multisite
Install Discourse on Plesk / Ubuntu 14 without Docker
I want to host hundreds of instances of Discourse
Three sites in one setup
Not receiving activation email for admin on multisite installation
Is it possible to totally hide members
Multiple discourse instances in a single server
Can I log into multiple instances of discourse simultaneously?
Adding an instance to multisite without rebuilding the container
Multiple communities on discourse?
Need help with multisite configuration
Multitenat Dockerize Discourse
Discourse Multisite – Nginx (Inside Docker) Only Serving Default Site
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
Does discourse hosting use docker for all customer instances?
Tips for setting up a multi-subdomain Discourse instance with shared SSO?
Move from standalone container to separate web and data containers
Move from standalone container to separate web and data containers
How can Admin login while Read-only mode is enabled on multisite?
Running multiple things on the same sever as my Pi (where Discourse is hosted)?
How extensible can I make my installation in terms of sub domains and restricting membership to them?
Discourse instance stops running in every midnight
One server for 2 Discourse communities?
One server for 2 Discourse communities?
Guidance on multi-site setup
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
Add path to cookie
App.yml shared volumes for a two website setup
Contabo experience with Plesk, Webmin or other server-admin setup?
Move from standalone container to separate web and data containers
Using a launcher built docker image in docker-compose
Two standalone instances on one server?
Best approach for test and production instance of discourse
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
(Obsolete) Set category tracking level defaults historically
Integration with .NET MVC application for a SaaS platform
Multisite for small collection of sites for a family?
Hosting Plan Suggestion for 500 Concurrent Online Users
Avatar, Site Logos, and Cert Errors
Database access issues after upgrade v3.5.2 -> v3.6.0.beta2
Secure cookie configuration
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
Installing on Kubernetes
How might we better structure #howto?
How to set redis DB ID in Docker container?
Run 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
Run other websites on the same machine as Discourse
Set up Let’s Encrypt with multiple domains / redirects
Set up Let’s Encrypt with multiple domains / redirects
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
Pups::ExecError
Web-only - do I need a separate image for each container?
All users are visible in @mentions autocomplete list
Migrate from VPS to a Dedicated

Me preguntaba qué hace el valor db_id: 2 en la configuración sugerida anteriormente.

Además, ¿cuál es el procedimiento para añadir un nuevo sitio a la configuración multisitio existente? ¿Es solo:

  • Actualizar yaml
  • ./launcher bootstrap multisite [1]
  • ./launcher start multisite

Me preguntaba si había alguna forma de evitar afectar a todos los demás sitios existentes al hacer un bootstrap o reconstrucción completa y de alguna manera solo añadir la base de datos adicional necesaria.


  1. Intenté ./launcher rebuild multisite primero, pero parece fallar. ↩︎

Creo que el id de la base de datos ya no es necesario.

Puedes editar el archivo multisite con el nuevo sitio y hacer un

sv restart unicorn

Y luego migrar la base de datos.

1 me gusta

¡Eres un salvavidas!

Me faltaba este comando para reiniciar (también probé sv reload unicorn pero de alguna manera no fue suficiente).

En cuanto a la creación de la base de datos, ¿ya existe una forma de hacerlo automáticamente? Sería bueno tener rake db:create[mynewdbname]. De lo contrario, puedo escribir un script corto.

En este momento, creo manualmente (creo la base de datos y establezco los permisos) y luego hago un RAILS_DB=newdb rake db:migrate para poblarla.

Y solo para comprobar si estoy haciendo algo estúpido:

  • Por el momento, estoy editando el archivo multisite dentro de docker (/var/www/discourse/config/multisite.yml)
  • Creando la base de datos manualmente
  • Ejecutando rake db:migrate
  • sv restart unicorn
  • Luego también tengo que editar el archivo yaml fuera de docker para que la configuración multisite esté sincronizada en caso de cualquier reconstrucción o actualización futura.

¿Estoy siendo tonto al editar la configuración multisite en 2 lugares diferentes cuando ya existe una forma de editar en un solo lugar y aplicar los cambios?

1 me gusta

¿Es posible limpiar un poco esta documentación y proporcionar más indicaciones en ella? Soy extremadamente nuevo en Docker, y aunque tengo experiencia en servidores Linux, no soy un profesional en ello. Soy de la vieja escuela, me encantan mis cron jobs y scripts de shell y cosas raras como esas con Apache multisite, etc. Pero esto es un poco más complejo y utiliza un lenguaje de programación diferente al que estoy acostumbrado… ¿Quizás incluso un video de demostración de algún tipo? Sería bueno si Discourse estuviera listo para multisite y de esa manera solo tendrías que editar algunos archivos, etc.

2 Me gusta

Simplemente pega esa estrofa de texto y edítala según sea necesario.

También necesitarás un proxy inverso o seguir Configurar Let’s Encrypt con múltiples dominios / redirecciones para obtener certificados para todos los dominios.

Consulta también Configuración de multisitio con Let’s Encrypt y sin proxy inverso. Pero esa necesita ser actualizada para tener otra línea requerida que puedes obtener del enlace anterior. He estado queriendo actualizarla pero no he podido.

1 me gusta

Si estoy haciendo multisitio, ¿a dónde debo apuntar mi dominio? ¿A la misma IP que el servidor (que aloja otro foro)?

Sí, apunta todos los dominios a la misma IP del servidor.
Configura un proxy inverso con el servidor Nginx o Caddy.
Caddy es el mejor, ya que proporciona certificados SSL automáticos gratuitos para todos tus dominios.

1 me gusta