Discourse is the premier modern, open-source community platform powering discussions for companies like OpenAI, Rust, GitHub, and Docker. While managed Discourse hosting starts at $50 to $100 per month, running Discourse on your own Linux cloud VPS costs as little as $10 per month while delivering complete data sovereignty and infinite customization options. This step-by-step guide covers the official containerized installation, swap configuration, automated Let’s Encrypt SSL, and SMTP mail configuration.
1. Discourse Infrastructure Architecture
Discourse is engineered as an enterprise Rails application designed to be deployed through an official Dockerized launcher. The base container encompasses:
- PostgreSQL 16: Modern relational database holding user accounts, posts, topics, badges, and revision history.
- Redis 7: Ultra-fast in-memory cache handling background queues, rate limiting, and real-time push events.
- Puma & Rails: Modern ruby web server processing dynamic forum requests.
- Sidekiq Workers: Asynchronous background job daemon handling digest emails, search indexing, and webhook dispatching.
- Built-in Nginx Proxy: Handles SSL termination, gzip compression, and HTTP/2 multiplexing directly inside the container.
2. Hardware & Cloud VPS Requirements
To run Discourse reliably in production without experiencing memory pressure crashes during Docker image rebuilds:
- RAM: 2 GB minimum (with a 2 GB swap file configured). 4 GB recommended for communities over 1,000 daily active users.
- Storage: 30 GB+ NVMe SSD storage to accommodate database backups and user media uploads.
- Operating System: Ubuntu 22.04 or 24.04 LTS 64-bit x86_64.
- Transactional SMTP Account: Discourse requires working email to send invitation codes, activation emails, and password resets (Mailgun, SendGrid, Amazon SES, or Postmark).
3. Step 1: Configuring SWAP on Ubuntu VPS
Even on 2 GB RAM servers, allocating a 2 GB swap file is mandatory to prevent Docker rebuild failures during Discourse upgrades:
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
# Optimize swappiness for database performance
sudo sysctl vm.swappiness=10
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
4. Step 2: Installing Docker Engine
Install official Docker engine using the official Docker repository:
sudo apt update && sudo apt install -y curl git apt-transport-https ca-certificates gnupg
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io
sudo systemctl enable --now docker
5. Step 3: Cloning Discourse Docker & Running Setup
Clone the official Discourse Docker repository into /var/discourse:
sudo git clone https://github.com/discourse/discourse_docker.git /var/discourse
cd /var/discourse
sudo chmod 700 containers
Launch the automated Discourse setup wizard:
sudo ./discourse-setup
The interactive wizard will prompt you for the following parameters:
- Hostname:
community.yourdomain.com(Ensure DNS A record points to your VPS IP beforehand). - Email for Admin Account: Your personal administrator email.
- SMTP server address: e.g.,
smtp.mailgun.orgoremail-smtp.us-east-1.amazonaws.com - SMTP port:
587 - SMTP user name: Your SMTP API user.
- SMTP password: Your SMTP API key or password.
- Let’s Encrypt Email: Used for automated SSL certificate issuance and expiration notices.
Once you confirm the inputs, the script generates containers/app.yml and builds the Docker container. This process compiles Ruby gems, precompiles Ember.js frontend bundles, and migrates the PostgreSQL database (takes 5-8 minutes).
6. Post-Installation Configuration & Automated Backups
Once the container is online, visit https://community.yourdomain.com to register your administrator profile. Configure automated cloud backups under Admin → Settings → Backups:
- Enable daily automatic backups.
- Retain last 7 backup cycles.
- Optionally sync backups offsite to Amazon S3 or Cloudflare R2 object storage.
Updating Discourse via Command Line
Whenever a security update or major version is released, update your instance seamlessly:
cd /var/discourse
git pull
sudo ./launcher rebuild app
7. Troubleshooting Discourse Deployments
| Issue | Root Cause | Resolution Action |
|---|---|---|
| Activation Email Not Received | SMTP port blocked or incorrect SMTP credentials | Test SMTP with ./launcher enter app then run Rails mailer test |
| Rebuild Fails with OOM Killed | Out of physical and virtual memory during assets compile | Increase swap size to 4 GB and retry ./launcher rebuild app |
| SSL Certificate Handshake Error | DNS A record not propagated prior to Let’s Encrypt challenge | Verify DNS using dig +short community.yourdomain.com before rebuild |
8. Tuning Discourse Background Queues & PostgreSQL Memory Allocation
As your Discourse community scales beyond the first 1,000 active discussions, tuning PostgreSQL and Sidekiq inside /var/discourse/containers/app.yml maximizes forum responsiveness:
- PostgreSQL Shared Buffers: Inside
app.yml, adjust thedb_shared_buffersparameter to 25% of total system RAM (e.g.,db_shared_buffers: "512MB"on a 2 GB VPS, or"1024MB"on a 4 GB VPS). - Sidekiq Concurrency: Default Sidekiq concurrency is tuned for modest servers. On multi-core CpanelFree VPS plans, increase background workers to process incoming email digests and notifications rapidly without backlogging the queue:
env: UNICORN_WORKERS: 3 DISCOURSE_SIDEKIQ_WORKERS: 5 - Rebuilding to Apply: Run
sudo ./launcher rebuild appto apply memory optimizations. The launcher automatically adjusts PostgreSQL’s internal query planner parameters based on the new buffers.
9. Securing Discourse with Cloudflare Full SSL & Origin Rules
Placing Cloudflare in front of your Discourse VPS adds a global CDN layer, DDoS mitigation, and Web Application Firewall (WAF) filtering. Ensure Cloudflare SSL mode is set to Full (Strict) and configure Cloudflare Page Rules to bypass caching for /session/* and administrative routes while caching static assets at edge POPs.
Host Your Community Forum on High-Speed CpanelFree Cloud
Power fast-growing Discourse communities with enterprise NVMe storage, dedicated RAM, and blazing network connectivity on CpanelFree VPS.
