Discourse is an open source comment and forum solution that can be run standalone or integrated with websites and blogging software like Ghost. Discourse can be self-hosted, but it has its own docker management solution which makes things more difficult when running on a NAS solution like the Synology.
This tutorial details how to get Discourse running on a Synology NAS using Docker. I use Discourse for the comments engine on this blog, which is running on Ghost.
- SSH access to the Synology
- Synology DSM 7.0-41890 or later.
- Synology setup for use with Docker, see my article <XYZ> for how I did this.
- Email provider setup for SMTP
- DNS name for the Discourse setup (eg: discourse.somedomainname.com)
- Let's Encrypt SSL certificate installed with the DNS name for the Discourse setup
- Optional: Maxmind GeoLite2 Account (https://www.maxmind.com/en/geolite2/signup)
Install Git command line utilities
The Discourse setup uses git commands, which are not installed by default on the Synology. To install the git command line tools, install the Git Server package from the Synology Package Manager.
Optional: Install Nano text editor
This technically isn't required, but personally I quite dislike VI and VIM, and much prefer Nano for text editing when in SSH. Nano is a much more user friendly text editor that you can install from community Synology packages. The instructions on doing this are here:
If you don't install Nano, just use VI or VIM anywhere I have a Nano command. Conversely you can always use the Synology GUI and use the Text Editor if you have the Text Editor package installed.
I do highly recommend installing the Text Editor package from Synology if it is not already installed. It is very convenient.
Gather Information For Install
Before starting the installation, gather some information that you will need during the installation. Gathering this information now and doing any additional setup you might need will be beneficial to do now. You will need the following information.
- Discourse Hostname - the DNS name you are going to use for your Discourse instance
- Email address for the admin account
- SMTP server address
- SMTP port
- SMTP username
- SMTP password
- Notification from email address
- Optional: Maxmind License key
Download the Discourse Docker Image
Login to the Synology via SSH. Once logged in, change to the root user to execute the remainder of the commands.
Clone the official Discourse Docker image to your Docker folder for Discourse.
git clone https://github.com/discourse/discourse_docker.git /volume1/docker/discourse
Create a symbolic link between the Docker folder for Discourse and where Discourse installer wants everything to be.
ln -s /volume1/docker/discourse /var/discourse
Create missing folders so that it doesn't error out on the build.
mkdir /var/discourse/shared/standalone mkdir /var/discourse/shared/standalone/log/ mkdir /var/discourse/shared/standalone/log/var-log
Copy over the standalone sample container to the correct location for setup, and at the same time rename the file to what you want to call the container.
cp /var/discourse/samples/standalone.yml /var/discourse/containers/discourse.yml
Edit the standalone container configuration for your environment.
The standard Discourse installation method doesn't work on the Synology. Therefore to make things work we need to modify the configuration file with the settings we want and then build the container from there.
First comment out HTTPS, since we will be using a reverse proxy on the Synology, we only want HTTP. Change the port from 80 to 4321, or some other port. The port can't be in use and should be above 1024.
expose: - "4321:80" # http # - "8443:443" # https
Set the various email configuration values. You may need to uncomment these as well as set them to the correct value.
DISCOURSE_DEVELOPER_EMAILS: 'email@example.com' DISCOURSE_SMTP_ADDRESS: smtp.email.com DISCOURSE_SMTP_PORT: 587 DISCOURSE_SMTP_USER_NAME: firstname.lastname@example.org DISCOURSE_SMTP_PASSWORD: pa$$word DISCOURSE_NOTIFICATION_EMAIL: email@example.com
Configure the Maxmind license key.
Build the Docker container.
/var/discourse/launcher rebuild discourse --skip-prereqs
The build process can take some time. It will spawn a bunch of other temporary containers and a lot of status messages to the console. Just wait and eventually it will finish. The process can take 10-30 minutes to fully complete.
Setup the Reverse Proxy
This installation leverages the Synology built in reverse proxy to enable SSL and route traffic. This is very handy if you run multiple containers and host other services, and also makes things more simple.
From the Synology GUI, go to Control Panel, then Login Portal, then Advanced. Click Reverse Proxy. Click Create.
The following values should be entered.
- Reverse Proxy Name: discourse
- Protocol: HTTPS
- Hostname: <This is the external URL to access your blog>
- Port: 443
- Check Enable HSTS
- Protocol : HTTP
- Hostname: localhost
- Port: 4321
It is important that you make sure your firewall/router is correctly setup to forward packets from TCP/443 to your Synology.
If you have multiple services all running on the Synology, they each should have a unique Source Hostname configured in the reverse proxy that matches the public DNS name. This is how the reverse proxy knows where to route the correct traffic. This way if you have multiple services that need TCP/443 publicly, they all get routed correctly through the Synology's reverse proxy.
Discourse Application Configuration
At this point Discourse should be running and you can use the Synology Docker application to monitor it.
The final steps are to finish configuration of Discourse by going to the new application at https://<your_URL_here>.
Documentation for finishing the Discourse application configuration as well as how to integrate Discourse into a Ghost blog is linked below in the references section.
Miscellaneous Notes: Let's Encrypt Certificate
Make sure your Let's Encrypt SSL certificate has the DNS name you are using for Discourse listed in its subject alternate name. You may have to add a new certificate, and replace the existing one, then add the new DNS name.
If you don't do this, you will get weird browser errors.
Miscellaneous Notes: --skip-prereqs
The Discourse launcher application does a check for the storage driver versus you are using. More often then not Synology users will be using btrfs which is not a supported file system driver for Discourse.
You have two choices to fix this:
- Use the --skip-prereqs command line option everytime you run the launch application
- Modify the launcher application and add the storage driver being used to the whitelist of storage drivers within the launcher application.
You should just use the --skip-prereqs command line options, but if you wanted to change the launcher application here is how you would do it.
Check the current storage driver used by Docker.
Look for Storage Driver: in the output. If it is either aufs, zfs, or overlay2 you can skip the rest of this section and move on to the Discourse Setup Tool Instructions.
If the Storage driver is anything else, you need to edit /var/discourse/launcher. You can use the Text Editor in the Synology GUI to do this or you can use nano from the SSH session.
Look for the line (around line 171 or so):
if ! $docker_path info 2> /dev/null | egrep -q 'Storage Driver: (aufs|zfs|overlay2)$'; then
and insert the storage driver listed in the docker info command, in my case btrfs. The end result would like like this.
if ! $docker_path info 2> /dev/null | egrep -q 'Storage Driver: (aufs|btrfs|zfs|overlay2)$'; then