Deploying a Discourse Forum
Introduction
Discourse is a modern, feature-rich, open-source discussion platform designed for civilized online communities. Built with Ruby on Rails and Ember.js, Discourse provides a powerful alternative to traditional forums with real-time updates, rich media embedding, comprehensive moderation tools, and mobile-responsive design. Whether you’re building a community for customers, developers, enthusiasts, or any other group, Discourse offers the tools needed to foster meaningful discussions and engagement.
Discourse stands out with its:
- Modern Interface: Clean, responsive design that works seamlessly on desktop and mobile devices
- Real-Time Updates: Live notifications, instant replies, and dynamic content loading
- Powerful Moderation: Advanced moderation tools, trust levels, and community management features
- Rich Content: Support for images, videos, code blocks, polls, and external media embedding
- Extensive Plugins: Large ecosystem of plugins and themes for customization
- SSO Integration: Single sign-on support for seamless authentication
- Email Integration: Full email support for notifications and posting via email
- Search & Discovery: Fast full-text search, categorization, and tagging systems
- Gamification: Badges, trust levels, and achievements to encourage engagement
This comprehensive guide walks you through deploying Discourse on Klutch.sh using Docker, covering installation steps, database configuration, persistent storage setup, environment variables, and production best practices.
Prerequisites
Before you begin deploying Discourse, ensure you have the following:
- A Klutch.sh account
- A GitHub account with a repository for your Discourse project
- Docker installed locally for testing (optional but recommended)
- Basic understanding of Docker, PostgreSQL, Redis, and Ruby applications
- A domain name for your Discourse forum (recommended for production)
Understanding Discourse Architecture
Before deployment, it’s important to understand Discourse’s architecture:
- Application Server: Ruby on Rails application serving the API and frontend
- PostgreSQL Database: Primary data store for all content, users, and configuration
- Redis: In-memory cache for sessions, job queues, and caching
- Sidekiq: Background job processor for emails, notifications, and maintenance tasks
- Nginx (optional): Reverse proxy for serving static assets and SSL termination
For Klutch.sh deployment, we’ll containerize Discourse with its dependencies, utilizing persistent volumes for data storage and external databases when needed.
Installation and Setup
Step 1: Create Your Project Directory
First, create a new directory for your Discourse deployment project:
mkdir discourse-klutchcd discourse-klutchgit initStep 2: Create the Dockerfile
Create a Dockerfile in your project root. This example uses the official Discourse Docker image as a base:
FROM discourse/base:2.0.20231030-0205
# Set working directoryWORKDIR /var/www/discourse
# Environment variables (override these in Klutch.sh dashboard)ENV RAILS_ENV=productionENV RUBY_GLOBAL_METHOD_CACHE_SIZE=131072ENV RUBY_GC_HEAP_GROWTH_MAX_SLOTS=40000ENV RUBY_GC_HEAP_INIT_SLOTS=400000ENV RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=1.5
# Clone Discourse (use specific version for production)RUN git clone https://github.com/discourse/discourse.git /var/www/discourse && \ cd /var/www/discourse && \ git checkout v3.1.3
# Install dependenciesRUN bundle install --deployment --without test development && \ yarn install --production --frozen-lockfile
# Precompile assets (optional, can be done at runtime)# RUN bundle exec rake assets:precompile
# Create necessary directoriesRUN mkdir -p /shared/log /shared/uploads /shared/backups
# Expose Discourse portEXPOSE 3000
# Copy entrypoint scriptCOPY docker-entrypoint.sh /usr/local/bin/RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0", "-p", "3000"]Note: This Dockerfile uses a specific Discourse version (v3.1.3). Check the Discourse releases page for the latest stable version.
Step 3: Create the Entrypoint Script
Create a docker-entrypoint.sh script to handle database migrations and initialization:
#!/bin/bashset -e
echo "Starting Discourse initialization..."
# Wait for PostgreSQL to be readyuntil PGPASSWORD=$DISCOURSE_DB_PASSWORD psql -h "$DISCOURSE_DB_HOST" -U "$DISCOURSE_DB_USERNAME" -d "$DISCOURSE_DB_NAME" -c '\q' 2>/dev/null; do echo "Waiting for PostgreSQL..." sleep 2done
echo "PostgreSQL is ready!"
# Wait for Redis to be readyuntil redis-cli -h "$DISCOURSE_REDIS_HOST" -p "${DISCOURSE_REDIS_PORT:-6379}" ping 2>/dev/null; do echo "Waiting for Redis..." sleep 2done
echo "Redis is ready!"
# Run database migrationsecho "Running database migrations..."bundle exec rake db:migrate
# Precompile assets if not done at build timeif [ ! -f "/var/www/discourse/public/assets/.sprockets-manifest-*.json" ]; then echo "Precompiling assets..." bundle exec rake assets:precompilefi
# Create admin user if this is first run (optional)# bundle exec rake admin:create
echo "Starting Discourse..."exec "$@"Step 4: Simplified Production Dockerfile
For a simpler setup using the official Discourse Docker image with minimal customization:
FROM discourse/discourse:3.1.3
# Set environmentENV RAILS_ENV=productionENV DISCOURSE_HOSTNAME=example-app.klutch.shENV DISCOURSE_DEVELOPER_EMAILS=admin@example.com
# Create shared directoriesRUN mkdir -p /shared/log /shared/uploads /shared/backups
# Expose portEXPOSE 3000
# Health checkHEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ CMD curl -f http://localhost:3000/srv/status || exit 1
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0", "-p", "3000"]This simplified version is easier to maintain and leverages the official image’s built-in configuration.
Step 5: Create Database Configuration File
Create a config/database.yml file for local testing:
production: adapter: postgresql database: <%= ENV['DISCOURSE_DB_NAME'] %> username: <%= ENV['DISCOURSE_DB_USERNAME'] %> password: <%= ENV['DISCOURSE_DB_PASSWORD'] %> host: <%= ENV['DISCOURSE_DB_HOST'] %> port: <%= ENV['DISCOURSE_DB_PORT'] || 5432 %> pool: <%= ENV['DISCOURSE_DB_POOL'] || 25 %> timeout: 5000 prepared_statements: false advisory_locks: trueStep 6: Create Environment Configuration
Create a .env.example file to document required environment variables:
# Discourse ConfigurationDISCOURSE_HOSTNAME=example-app.klutch.shDISCOURSE_DEVELOPER_EMAILS=admin@example.com
# Database ConfigurationDISCOURSE_DB_HOST=postgres.example.comDISCOURSE_DB_PORT=5432DISCOURSE_DB_NAME=discourseDISCOURSE_DB_USERNAME=discourseDISCOURSE_DB_PASSWORD=your-secure-password
# Redis ConfigurationDISCOURSE_REDIS_HOST=redis.example.comDISCOURSE_REDIS_PORT=6379DISCOURSE_REDIS_PASSWORD=
# SMTP Configuration (for emails)DISCOURSE_SMTP_ADDRESS=smtp.example.comDISCOURSE_SMTP_PORT=587DISCOURSE_SMTP_USERNAME=noreply@example.comDISCOURSE_SMTP_PASSWORD=smtp-passwordDISCOURSE_SMTP_ENABLE_START_TLS=true
# S3 Configuration (optional, for uploads)DISCOURSE_USE_S3=falseDISCOURSE_S3_BUCKET=DISCOURSE_S3_REGION=DISCOURSE_S3_ACCESS_KEY_ID=DISCOURSE_S3_SECRET_ACCESS_KEY=
# SecurityDISCOURSE_SECRET_KEY_BASE=generate-with-rake-secretSecurity Note: Never commit actual passwords or sensitive data to your repository. These should be set as environment variables in the Klutch.sh dashboard.
Step 7: Create README Documentation
Create a README.md file with deployment instructions:
# Discourse on Klutch.sh
This repository contains the Docker configuration for deploying Discourse on Klutch.sh.
## Requirements
- PostgreSQL 13+ database- Redis 6+ instance- Persistent storage for uploads and backups- SMTP server for email delivery
## Environment Variables
See `.env.example` for all required environment variables.
## Deployment
1. Deploy PostgreSQL and Redis instances on Klutch.sh2. Create persistent volumes for uploads and backups3. Set environment variables in Klutch.sh dashboard4. Deploy this repository
## First-Time Setup
After deployment, create your admin user:
```bashRAILS_ENV=production bundle exec rake admin:createUpdating Discourse
To update to a new version, change the version in the Dockerfile and redeploy.
### Step 8: Push to GitHub
Commit your files and push to GitHub:
```bashgit add Dockerfile docker-entrypoint.sh .env.example README.mdgit commit -m "Add Discourse Docker configuration"git remote add origin https://github.com/yourusername/discourse-klutch.gitgit push -u origin mainSetting Up Database Dependencies
Discourse requires both PostgreSQL and Redis to function. You’ll need to set these up before deploying Discourse.
PostgreSQL Setup
-
Deploy PostgreSQL on Klutch.sh
Create a new app for PostgreSQL using the official PostgreSQL Docker image:
FROM postgres:15-alpineENV POSTGRES_DB=discourseENV POSTGRES_USER=discourse# Set POSTGRES_PASSWORD via environment variables in Klutch.shEXPOSE 5432 -
Configure PostgreSQL Volume
Attach a persistent volume to ensure your database persists:
- Mount Path:
/var/lib/postgresql/data - Size: At least 10GB (recommended 20GB+ for production)
- Mount Path:
-
Set PostgreSQL Traffic Type
- Traffic Type: Select TCP
- Internal Port:
5432 - External Port:
8000(this is where you’ll connect from Discourse)
-
Note Connection Details
Your PostgreSQL connection will be available at:
Host: your-postgres-app.klutch.shPort: 8000Database: discourseUsername: discoursePassword: (set in environment variables)
Redis Setup
-
Deploy Redis on Klutch.sh
Create a new app for Redis:
FROM redis:7-alpine# Optional: Enable persistenceCMD ["redis-server", "--appendonly", "yes"]EXPOSE 6379 -
Configure Redis Volume (optional but recommended)
Attach a persistent volume for Redis data:
- Mount Path:
/data - Size: 5GB (adjust based on cache needs)
- Mount Path:
-
Set Redis Traffic Type
- Traffic Type: Select TCP
- Internal Port:
6379 - External Port:
8000(connect from Discourse on this port)
-
Note Connection Details
Your Redis connection will be:
Host: your-redis-app.klutch.shPort: 8000
Deploying to Klutch.sh
Now that your dependencies are set up, deploy the Discourse application.
Deployment Steps
-
Log in to Klutch.sh
Navigate to klutch.sh/app and sign in to your account.
-
Create a New Project
Go to Create Project and give your project a meaningful name (e.g., “Discourse Forum”).
-
Create the Discourse App
Navigate to Create App and configure the following settings:
-
Select Your Repository
- Choose GitHub as your Git source
- Select the repository containing your Dockerfile
- Choose the branch you want to deploy (usually
main)
-
Configure Traffic Type
- Traffic Type: Select HTTP (Discourse serves a web application via HTTP)
- Internal Port: Set to
3000(the default port that Discourse listens on)
-
Set Environment Variables
Add the following environment variables (use the connection details from your PostgreSQL and Redis deployments):
Database Configuration:
DISCOURSE_DB_HOST: Your PostgreSQL app hostname (e.g.,postgres-app.klutch.sh)DISCOURSE_DB_PORT:8000(external port for TCP traffic)DISCOURSE_DB_NAME:discourseDISCOURSE_DB_USERNAME:discourseDISCOURSE_DB_PASSWORD: Strong password for databaseDISCOURSE_DB_POOL:25(connection pool size)
Redis Configuration:
DISCOURSE_REDIS_HOST: Your Redis app hostname (e.g.,redis-app.klutch.sh)DISCOURSE_REDIS_PORT:8000(external port for TCP traffic)
Discourse Configuration:
DISCOURSE_HOSTNAME: Your Discourse URL (e.g.,forum.example.comorexample-app.klutch.sh)DISCOURSE_DEVELOPER_EMAILS: Admin email addresses (comma-separated)RAILS_ENV:productionDISCOURSE_SECRET_KEY_BASE: Generate usingrake secretcommand (64+ character random string)
SMTP Configuration (for emails):
DISCOURSE_SMTP_ADDRESS: Your SMTP server addressDISCOURSE_SMTP_PORT: SMTP port (usually587or465)DISCOURSE_SMTP_USERNAME: SMTP usernameDISCOURSE_SMTP_PASSWORD: SMTP passwordDISCOURSE_SMTP_ENABLE_START_TLS:true(for port 587)
Optional S3 Configuration (for uploads):
DISCOURSE_USE_S3:true(if using S3 for uploads)DISCOURSE_S3_BUCKET: Your S3 bucket nameDISCOURSE_S3_REGION: S3 regionDISCOURSE_S3_ACCESS_KEY_ID: AWS access keyDISCOURSE_S3_SECRET_ACCESS_KEY: AWS secret key
-
Attach Persistent Volumes
Discourse requires persistent storage for uploads, backups, and logs:
Uploads Volume:
- Click “Add Volume”
- Mount Path:
/shared/uploads - Size: 20GB+ (adjust based on expected usage)
Backups Volume:
- Click “Add Volume”
- Mount Path:
/shared/backups - Size: 10GB+ (for database backups)
Logs Volume (optional):
- Click “Add Volume”
- Mount Path:
/shared/log - Size: 5GB
-
Configure Resource Allocation
Discourse is resource-intensive, especially with active communities:
- CPU: Minimum 1 CPU, recommended 2+ CPUs for active forums
- Memory: Minimum 2GB RAM, recommended 4GB+ for production
- Instances: Start with 1 instance (scale horizontally as traffic grows)
-
Deploy Your Application
Click “Create” to start the deployment. Klutch.sh will:
- Automatically detect your Dockerfile in the repository root
- Build the Docker image with Discourse
- Attach the persistent volumes
- Configure networking to databases
- Start your Discourse container
- Assign a URL for external access
-
Wait for Deployment
The initial deployment may take 5-10 minutes as Discourse:
- Installs dependencies
- Runs database migrations
- Precompiles assets
- Starts the Rails server
Monitor the logs in the Klutch.sh dashboard to track progress.
-
Access Your Discourse Forum
Once deployment is complete, navigate to your assigned URL:
https://example-app.klutch.shYou should see the Discourse setup wizard for first-time configuration.
Initial Configuration and Admin Setup
After your Discourse instance is running, complete the initial setup:
Creating Your Admin Account
-
Access the Setup Wizard
Navigate to your Discourse URL and you’ll be prompted to create an admin account.
-
Register Your Account
Fill in the registration form with:
- Username
- Email (must match one in
DISCOURSE_DEVELOPER_EMAILS) - Password (use a strong password)
-
Configure Basic Settings
The wizard will guide you through:
- Site title and description
- Contact email
- Category setup
- Upload settings
- Login methods
-
Verify Email Configuration
Check that email is working by sending a test email from the admin panel.
Manual Admin Creation (if needed)
If you need to create an admin account manually via command line:
# SSH into your container or use Klutch.sh consolecd /var/www/discourseRAILS_ENV=production bundle exec rake admin:create
# Follow the prompts to create admin user# Email: admin@example.com# Password: (enter secure password)# Repeat Password: (confirm password)Environment Variables Reference
Complete reference of Discourse environment variables:
| Variable | Description | Required | Default |
|---|---|---|---|
DISCOURSE_HOSTNAME | Public hostname for your forum | Yes | None |
DISCOURSE_DEVELOPER_EMAILS | Admin email addresses (comma-separated) | Yes | None |
DISCOURSE_DB_HOST | PostgreSQL host | Yes | None |
DISCOURSE_DB_PORT | PostgreSQL port | Yes | 5432 |
DISCOURSE_DB_NAME | PostgreSQL database name | Yes | discourse |
DISCOURSE_DB_USERNAME | PostgreSQL username | Yes | None |
DISCOURSE_DB_PASSWORD | PostgreSQL password | Yes | None |
DISCOURSE_DB_POOL | Database connection pool size | No | 25 |
DISCOURSE_REDIS_HOST | Redis host | Yes | None |
DISCOURSE_REDIS_PORT | Redis port | No | 6379 |
DISCOURSE_REDIS_PASSWORD | Redis password (if auth enabled) | No | None |
DISCOURSE_SECRET_KEY_BASE | Secret key for sessions | Yes | None |
RAILS_ENV | Rails environment | Yes | production |
DISCOURSE_SMTP_ADDRESS | SMTP server address | Yes | None |
DISCOURSE_SMTP_PORT | SMTP port | Yes | 587 |
DISCOURSE_SMTP_USERNAME | SMTP username | Yes | None |
DISCOURSE_SMTP_PASSWORD | SMTP password | Yes | None |
DISCOURSE_SMTP_ENABLE_START_TLS | Enable STARTTLS | No | true |
DISCOURSE_USE_S3 | Use S3 for uploads | No | false |
DISCOURSE_S3_BUCKET | S3 bucket name | If using S3 | None |
DISCOURSE_S3_REGION | S3 region | If using S3 | None |
DISCOURSE_S3_ACCESS_KEY_ID | AWS access key | If using S3 | None |
DISCOURSE_S3_SECRET_ACCESS_KEY | AWS secret key | If using S3 | None |
DISCOURSE_CDN_URL | CDN URL for assets | No | None |
DISCOURSE_MAXMIND_LICENSE_KEY | MaxMind GeoIP license key | No | None |
Production Best Practices
Security Recommendations
- HTTPS Only: Always use HTTPS for your Discourse forum. Use Klutch.sh’s automatic TLS or configure a custom domain with SSL.
- Strong Passwords: Use a password manager to generate strong passwords for all accounts and services.
- Environment Variables: Store all sensitive credentials as environment variables in Klutch.sh, never in your Dockerfile or code.
- Regular Updates: Keep Discourse updated to the latest stable version for security patches and features.
- Database Security: Use strong passwords for PostgreSQL and restrict access to database ports.
- Rate Limiting: Configure rate limiting in Discourse to prevent abuse and DDoS attacks.
- Two-Factor Authentication: Enable 2FA for admin accounts in Discourse settings.
- Backup Strategy: Implement regular backups of your database and uploads (see backup section below).
- Security Headers: Ensure proper security headers are configured (Discourse includes good defaults).
- Plugin Security: Only install trusted plugins from the official Discourse meta forum.
Performance Optimization
- Database Connection Pool: Adjust
DISCOURSE_DB_POOLbased on your traffic (default: 25). - Redis Memory: Allocate sufficient memory to Redis for caching (recommended: 512MB-2GB).
- Asset Precompilation: Precompile assets during build time to reduce startup time.
- CDN Integration: Use a CDN for static assets by setting
DISCOURSE_CDN_URL. - S3 for Uploads: For high-traffic sites, use S3 for uploads to reduce storage costs and improve performance.
- Database Optimization: Regularly run
VACUUMandANALYZEon PostgreSQL. - Sidekiq Workers: Monitor background job queue length and add workers if needed.
- Nginx Caching: Consider adding Nginx as a reverse proxy with caching for static assets.
- Image Optimization: Enable Discourse’s automatic image optimization features.
- Read Replicas: For very large forums, consider PostgreSQL read replicas.
Monitoring and Maintenance
Monitor your Discourse deployment for:
- Application Performance: Response times, error rates, and throughput
- Database Performance: Query times, connection pool usage, and slow queries
- Redis Performance: Memory usage, cache hit rate, and connection counts
- Background Jobs: Sidekiq queue length and job processing times
- Disk Usage: Monitor uploads, backups, and log file sizes
- Memory Usage: Track Rails and Sidekiq memory consumption
- CPU Usage: Monitor CPU utilization under load
- Email Delivery: Check SMTP logs for delivery failures
Backup and Disaster Recovery
-
Database Backups
Set up automated PostgreSQL backups:
Terminal window # Manual backuppg_dump -h $DISCOURSE_DB_HOST -U $DISCOURSE_DB_USERNAME -d $DISCOURSE_DB_NAME > discourse-backup-$(date +%Y%m%d).sqlSchedule regular backups using cron or a backup service.
-
Discourse Built-in Backups
Use Discourse’s built-in backup system:
- Navigate to Admin → Backups
- Click “Backup” to create a full backup
- Backups are stored in
/shared/backups - Download and store backups externally
-
Volume Snapshots
Utilize Klutch.sh volume snapshot features to backup:
/shared/uploads(user uploads)/shared/backups(discourse backups)- PostgreSQL data volume
-
Restore Process
To restore from backup:
Terminal window # Restore databasepsql -h $DISCOURSE_DB_HOST -U $DISCOURSE_DB_USERNAME -d $DISCOURSE_DB_NAME < discourse-backup.sql# Or use Discourse restoreRAILS_ENV=production bundle exec rake backup:restore BACKUP_FILE=filename
Customization and Plugins
Installing Plugins
Discourse has a rich plugin ecosystem. To install plugins:
-
Create a plugins directory in your repo
Terminal window mkdir -p plugins -
Add plugin as git submodule
Terminal window cd pluginsgit submodule add https://github.com/discourse/discourse-solved.gitgit submodule add https://github.com/discourse/discourse-voting.git -
Update Dockerfile to install plugins
# After cloning DiscourseCOPY plugins/ /var/www/discourse/plugins/# Install plugin dependenciesRUN cd /var/www/discourse && \bundle install --deployment --without test development -
Rebuild and deploy
Popular plugins:
- Discourse Solved - Mark topics as solved
- Discourse Voting - Add voting to topics
- Discourse Sitemap - SEO sitemap generation
- Chat Integration - Slack, Discord, etc.
Customizing Themes
Customize your forum’s appearance:
-
Admin Panel Method (recommended):
- Navigate to Admin → Customize → Themes
- Click “Install” and enter theme repository URL
- Activate the theme
-
Custom CSS:
- Admin → Customize → Themes → Edit CSS/HTML
- Add custom CSS, headers, or footers
-
Creating Custom Themes:
- Fork an existing theme repository
- Customize colors, fonts, and layouts
- Install via Admin panel
Scaling Your Discourse Forum
As your community grows, you may need to scale your Discourse deployment:
Vertical Scaling
Increase resources for your existing instance:
- Upgrade CPU: Move to 2, 4, or more CPUs
- Increase Memory: Scale to 4GB, 8GB, or more RAM
- Expand Storage: Increase volume sizes as needed
Horizontal Scaling
For very large communities:
- Web Servers: Run multiple Discourse app instances behind a load balancer
- Sidekiq Workers: Deploy dedicated Sidekiq workers for background jobs
- Database: Use PostgreSQL read replicas for read-heavy workloads
- Redis: Consider Redis clustering for large caches
- CDN: Offload static assets to a CDN
Caching Strategies
- Enable Discourse’s built-in caching features
- Use Redis effectively for session and cache storage
- Consider adding Varnish or Nginx caching layer
- Implement browser caching for static assets
Troubleshooting
Cannot Access Discourse Forum
- Check app status: Verify the app is running in Klutch.sh dashboard
- Verify port: Ensure internal port is set to
3000 - Traffic type: Confirm HTTP traffic type is selected
- Review logs: Check application logs for startup errors
- Database connectivity: Verify PostgreSQL is accessible
- Redis connectivity: Ensure Redis is reachable
Database Connection Errors
- Connection refused: Verify PostgreSQL is running and accessible on port 8000
- Authentication failed: Check database credentials in environment variables
- Database not found: Ensure database exists; create with
createdb discourse - Network issues: Verify both apps can communicate on Klutch.sh network
- Connection pool exhausted: Increase
DISCOURSE_DB_POOLvalue
Redis Connection Errors
- Cannot connect: Verify Redis is running and accessible on port 8000
- Timeout errors: Check Redis performance and memory limits
- Memory issues: Increase Redis memory allocation
- Persistence problems: Verify Redis volume is correctly mounted
Email Not Sending
- SMTP configuration: Verify all SMTP environment variables are correct
- Authentication: Check SMTP username and password
- Port blocked: Try different SMTP ports (587, 465, 25)
- TLS/SSL: Ensure
DISCOURSE_SMTP_ENABLE_START_TLSmatches your SMTP server - Test email: Send test email from Admin → Email settings
Slow Performance
- Check resources: Monitor CPU and memory usage in Klutch.sh
- Database queries: Review slow query logs in PostgreSQL
- Redis memory: Ensure Redis has sufficient memory allocated
- Sidekiq backlog: Check background job queue length
- Asset compilation: Ensure assets are precompiled
- Scale resources: Consider upgrading CPU/memory or scaling horizontally
Upload Failures
- Volume mounted: Verify
/shared/uploadsvolume is correctly attached - Permissions: Check directory permissions in container
- Disk space: Ensure sufficient space in uploads volume
- S3 configuration: If using S3, verify credentials and bucket access
- File size limits: Check Discourse and Nginx file size limits
Migration Errors
- Database version: Ensure PostgreSQL version compatibility (13+)
- Pending migrations: Run
bundle exec rake db:migratemanually - Failed migrations: Check logs for specific migration errors
- Rollback: If needed, rollback with
bundle exec rake db:rollback
Asset Compilation Fails
- Memory issues: Increase container memory for asset compilation
- Node.js version: Ensure compatible Node.js version in image
- Yarn lockfile: Verify
yarn.lockis present and valid - Precompile at build: Move asset compilation to Dockerfile
- Clear cache: Try
bundle exec rake assets:clobberand recompile
Upgrading Discourse
To upgrade Discourse to a new version:
Minor Version Updates
-
Update Dockerfile version:
# Change from v3.1.3 to v3.1.4git checkout v3.1.4 -
Test locally (optional but recommended):
Terminal window docker build -t discourse-test .docker run -it discourse-test -
Commit and push:
Terminal window git add Dockerfilegit commit -m "Upgrade Discourse to v3.1.4"git push -
Klutch.sh will automatically rebuild and deploy
Major Version Updates
For major version updates (e.g., v3.0 to v3.1):
- Review release notes: Check Discourse releases for breaking changes
- Backup everything: Create full database and uploads backup
- Test in staging: If possible, test upgrade in a staging environment
- Update Dockerfile: Change version in Dockerfile
- Review migrations: Check for any required manual migrations
- Deploy: Push changes and monitor deployment carefully
- Verify: Test critical functionality after upgrade
Rollback Procedure
If an upgrade fails:
- Revert Dockerfile: Change back to previous version
- Push changes: Klutch.sh will rebuild with old version
- Restore database: If database migrations occurred, restore from backup
- Investigate: Review logs to understand what went wrong
Advanced Configuration
Custom Domain Setup
To use a custom domain for your Discourse forum:
- Add domain in Klutch.sh: Navigate to your app settings and add custom domain
- Configure DNS: Point your domain to the provided Klutch.sh address
- Update environment variable: Set
DISCOURSE_HOSTNAMEto your custom domain - Verify SSL: Klutch.sh automatically provisions SSL certificates
- Redeploy: Restart your app to pick up new hostname
SSO Integration
Discourse supports Single Sign-On for seamless authentication:
- Configure SSO provider: Set up your SSO provider (OAuth2, SAML, etc.)
- Install plugin: Install appropriate SSO plugin for your provider
- Set environment variables:
DISCOURSE_SSO_URL=https://sso.example.comDISCOURSE_SSO_SECRET=your-sso-secret
- Enable in admin: Configure SSO settings in Discourse admin panel
CDN Configuration
For improved performance with a CDN:
- Set up CDN: Configure your CDN to point to your Discourse instance
- Add environment variable:
DISCOURSE_CDN_URL=https://cdn.example.com
- Configure CORS: Ensure CORS headers allow CDN domain
- Update asset URLs: Discourse will automatically use CDN for assets
Custom Email Templates
Customize email templates sent by Discourse:
- Access admin panel: Navigate to Admin → Customize → Email Templates
- Select template: Choose template to customize (welcome email, digest, etc.)
- Edit content: Modify subject and body with custom text and styling
- Use variables: Leverage Discourse template variables for personalization
- Preview: Test emails before making changes live
Additional Resources
- Discourse Official Website
- Discourse GitHub Repository
- Discourse Meta Community
- Official Discourse Documentation
- Klutch.sh Volumes Guide
- Klutch.sh Networking Guide
- Klutch.sh Custom Domains Guide
- Discourse Docker Images
- Discourse Plugins Directory
Conclusion
Deploying Discourse on Klutch.sh with Docker provides a robust, scalable platform for building online communities. By following this comprehensive guide, you’ve set up a production-ready Discourse instance with proper database configuration, persistent storage, security measures, and performance optimizations. Your community platform is now ready to foster engaging discussions and grow your online community. Remember to keep Discourse updated, monitor performance, maintain regular backups, and customize your forum to meet your community’s unique needs.