Deploy a Discourse Forum on Ubuntu with Docker

By Anurag Singh

Updated on Feb 17, 2025

Deploy a Discourse Forum on Ubuntu with Docker

In this tutorial, we'll learn how to deploy a Discourse forum on Ubuntu with Docker. 

Discourse redefines online discussions with its modern, user-friendly interface and robust community tools. It transforms the traditional forum experience by streamlining conversations, making them more intuitive and engaging. With features like real-time notifications, seamless integrations, and extensive plugin support, Discourse empowers both small communities and large organizations to foster meaningful dialogue in a secure, scalable environment.

We’ll walk through setting up a robust Discourse forum on an Ubuntu 24.04 server using Docker. You’ll learn how to configure your environment step by step—from updating your system and installing Docker to integrating SSL with Let’s Encrypt, setting up email notifications for user interactions, and managing plugins to extend functionality.

Whether you're a seasoned IT professional or looking to deepen your technical expertise, this detailed tutorial provides the insights you need to build a secure, scalable forum platform that caters to today’s online community requirements.

Prerequisites:

Deploy a Discourse Forum on Ubuntu with Docker

Step 1. Prepare Your Ubuntu Server

Before you install anything, make sure your server is up to date.

Log In and Update Packages:

Open your terminal (or connect via SSH) and run:

sudo apt update && sudo apt upgrade -y

This ensures your system has the latest security patches and software updates.

Install Essential Tools

You might need Git to clone repositories and other basic tools:

sudo apt install -y git curl

Step 2. Install Docker and Docker Compose

Discourse runs inside a Docker container, so you must have Docker installed.

Install Docker:

Use the convenience script provided by Docker:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

This script detects your system and installs the latest stable Docker version.

Manage Docker as a Non-root User (Optional):

If you don’t want to use sudo every time you run Docker commands:

sudo usermod -aG docker ${USER}

Log out and log back in (or restart your SSH session) to apply the changes.

Verify Docker Installation:

Run:

docker --version

You should see the Docker version information.

Install Docker Compose (if needed):

On newer Ubuntu versions Docker Compose might already be included. To install or verify:

sudo apt install docker-compose -y
docker-compose --version

Step 3. Clone the Discourse Docker Repository

Discourse provides a Dockerized version that simplifies installation.

Create a Directory for Discourse:

It’s common to use /var/discourse:

sudo mkdir /var/discourse
sudo chown ${USER}:${USER} /var/discourse

Clone the Repository:

Inside your new directory, clone the official Discourse Docker repo:

cd /var/discourse
git clone https://github.com/discourse/discourse_docker.git .

This command downloads all the necessary files, including the configuration templates and launcher scripts.

Step 4. Run the Discourse Setup Script

The repository includes a convenient setup script that will prompt you for your configuration details.

Start the Setup Process:

From within /var/discourse, run:

sudo ./discourse-setup

This script will ask you several questions. It’s interactive and designed to configure your forum properly.

Answer the Prompts:

You’ll be asked for:

  • Hostname: The domain name of your forum (e.g., forum.yourdomain.com). This is critical because Let’s Encrypt (which handles SSL) uses this domain to issue certificates.
  • Email Address: This is used for administrative notifications and SSL certificate registration with Let’s Encrypt.
  • SMTP Settings: To enable email notifications, provide your SMTP server details:
  • SMTP server address (e.g., smtp.gmail.com or your company’s SMTP server)
  • SMTP port (typically 587 for TLS or 465 for SSL)
  • SMTP username and password

Note: If you’re using Gmail or another provider with enhanced security, you may need to create an app password or adjust security settings.

Let’s Encrypt Integration (SSL Setup):

  • When prompted, confirm that you want to use Let’s Encrypt. The script will automatically request and install an SSL certificate for your domain.
  • Deep Insight: Discourse’s built-in integration means that you don’t have to manually obtain certificates. Once your DNS is correctly configured (i.e., your domain points to your server’s IP), Let’s Encrypt can verify your domain and issue the certificate.

Wait for the Setup to Complete:

The script pulls the necessary Docker image (a process that might take several minutes on a slow connection) and sets up the container. Once it finishes, you’ll have a running Discourse instance.

Step 5. Understanding SSL and Email Configuration

It’s important to grasp how SSL and email notifications are configured, as they are critical for user trust and engagement.

SSL via Let’s Encrypt:

  • Automatic Certificate Issuance: By supplying your domain and admin email during setup, Discourse uses Let’s Encrypt to get a free SSL certificate.
  • Renewal Process: The container includes a cron job that automatically renews your certificate before it expires.
  • Custom Certificates: If you prefer using your own certificates, you can modify the container configuration after installation. However, the Let’s Encrypt option is most straightforward for most users.

Email Notifications Setup:

  • SMTP Integration: Discourse needs to send emails (for account confirmations, password resets, and notifications). During setup, you provided SMTP details.
  • Test Emails: Once Discourse is running, log in as the admin and trigger a test email from the settings. If emails don’t arrive, double-check your SMTP credentials and, if using Gmail, verify that your account settings allow SMTP relay.
  • Debugging Email Issues: The Discourse logs (accessible from within the container) can provide insights if something isn’t working with your email configuration.

Step 6. Managing Plugins in Discourse

Discourse is built with extensibility in mind. Plugins add features and integrations, and you can manage them through the Docker configuration.

Locate the App Configuration File:

The primary configuration file is containers/app.yml within your /var/discourse directory. Open it with your favorite text editor:

nano /var/discourse/containers/app.yml

Adding a Plugin:

Inside app.yml, look for the section that lists additional Git repositories under hooks: or a similar key (often named templates or plugins). For example, you might see a section like:

templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"

To add a plugin, append its Git repository URL. For example, to add a hypothetical plugin:

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/example/discourse-awesome-plugin.git

This snippet tells the container to clone the plugin repository into the plugins directory when the container is built.

Rebuild the Container:

After modifying app.yml, rebuild your Discourse container to apply the changes:

sudo ./launcher rebuild app

Deep Insight: Rebuilding the container re-runs the configuration scripts, installs new plugins, and ensures everything is integrated properly. Expect a few minutes of rebuild time.

Plugin-Specific Configuration:

Some plugins might require additional settings. Consult the plugin’s documentation for any environment variables or additional configuration changes you need to add to app.yml or within the Discourse admin panel.

Step 7. Final Testing and Administration

Access Your Forum:

Once everything is set up, open a web browser and navigate to your domain (e.g., https://forum.yourdomain.com). You should see the Discourse welcome page. The presence of HTTPS confirms that SSL is active.

Admin Panel:

Log in with the credentials you set up during installation. Explore the admin panel where you can adjust site settings, manage plugins, and monitor activity.

Monitor Logs:

To view logs for debugging or simply monitoring activity, you can access the logs from the host:

sudo ./launcher logs app

This command streams the container logs to your terminal.

Backup Considerations:

Discourse recommends setting up regular backups. In the admin interface, you can configure backup frequency and storage options. If you ever need to restore your forum, these backups will be crucial.

Conclusion

By following these steps, you’ve deployed a Discourse forum on Ubuntu with Docker. You’ve set up secure HTTPS with Let’s Encrypt, configured email notifications to keep your community engaged, and learned how to extend functionality with plugins. Each part of this process—Docker management, SSL configuration, email setup, and plugin integration—plays a vital role in running a robust, secure forum. As you gain familiarity, you can tweak settings and explore more advanced features to customize your forum further.

Happy hosting and community building!