Discourse(s) on Docker

One of the things Tim built a while ago is a server running multiple instances of the forum software Discourse using Docker. He did this because we’re getting more and more interest at Reclaim Hosting for this forum software. As usual, Tim came up with a pretty slick setup that enables us to provide this fairly easily and cheaply. To be clear, I have not yet gone through the process of setting up the server environment that runs multiple Docker instances of Discourse, and I want to go through that process next. But in the interim, this post will simply go through setting up a new instance of Discourse using Docker in an attempt to beef up our internal documentation.

If you are interested in getting up and running with Discourse in a Docker container, check out Sam Saffron’s excellent overview of Docker, the various issues installing it, and a write-up of his process, I used that posts on several occasions to be refreshed on the commands I needed to bootstrap and start the docker container.

So, after logging into your server via command line (are you still with me?), you would change directories to where the containers setup files for each server are kept:

cd /var/discourse/containers


Discourse 1

You can see in the image above I was searching a bit. In the containers directory you have several .yml files for each of the Discourse installs. YAML files are basically a serialized set of instructions for Docker on how to setup the environment. You have to create a new YAML file for each new install, and then copy another install’s config and change a few details.  So, edit another YAML file by typing something like this:

nano nameofanothercontainer.yml

You will then be shown the config file for that container. Copy it and then create a new YAML file like so:

nano bava.yml

Copy the contents from the other container in this new file, and change the following details.

In this bit you include the email, or emails, of the admins:

## TODO: List of comma delimited emails that will be made admin and developer
## on initial signup example 'user1@example.com,user2@example.com'
DISCOURSE_DEVELOPER_EMAILS: 'info@reclaimhosting.com,jimgroom@gmail.com'

In the following area you change the hostname to the domain (or subdomain) you will be installing Discourse. Chances are you will be mapping an A-Record here (more on that later):

## TODO: The domain name this Discourse instance will respond to

In this area you need to setup your mail server info so Discourse can send emails to new users, etc. We use Mandrill for this at Reclaim Hosting, and it seems to work well. This is a big difference from applications in a LAMP environment which have all this setup for you. With the new fangled Rudy and Node.js apps you’ll find you need a transactional mail service like Mandrill, Mailgun, etc. —which are basically API driven mail services for developers, or so I’ve heard.

## TODO: The mailserver this Discourse instance will use
DISCOURSE_SMTP_ADDRESS: smtp.mandrillapp.com # (mandatory)
#DISCOURSE_SMTP_ENABLE_START_TLS: true # (optional, default true)

Finally, you need to change a few paths to point to your Discourse file. So anywhere you see bava was previously the name of the container’s YAML file I copy and pasted from. For example, if I copy and pasted from the reclaim.yml file, everywhere you see bava below would have originally been reclaim

## These containers are stateless, all data is stored in /shared
- volume:
    host: /var/discourse/shared/bava
    guest: /shared
- volume:
    host: /var/discourse/shared/bava/log/var-log
    guest: /var/log

Now save the bava.yml file.

After that, we need to edit the discourse settings for Nginx. Notice that Discourse is a Ruby application running on Nginx—two big reasons this application doesn’t run in a LAMP environment. Nginx is a web server, like Apache, but with different requirements than what’s bundled with a LAMP stack. Very few Ruby applications run in a LAMP environment, which means a whole generation of Ruby and Node.js web apps depend on a sysadmin to get running. One of the many reasons to be excited about Docker is that it can potentially make hosting these applications a lot easier. Anyway, we still have to edit Nginx.

Discourse 5

Go to:

cd /etc/nginx/sites-available

From there you need to edit the discourse file:

nano discourse

There will be a series of server settings for each of the discourse containers running. Copy one, and paste it at the end of the file and edit it to work for your container. For example, I replaced the URL I am running my container at (discourse.) as well as putting bava in the proxy_pass file path:

server {

        listen 80;

        # change this

        server_name discourse.;

        client_max_body_size 100M;

        location / {

        proxy_pass http://unix:/var/discourse/shared/bava/nginx.http.sock:;

                proxy_set_header Host $http_host;

                proxy_http_version 1.1;

                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;



Now you need to go to the /var/discourse directory and bootstrap the container and then run it. Below are the commands. When you bootstrap it will take a little while, because that is where an image of your discourse application is being created in the container.

sudo ./launcher bootstrap bava

Discourse 8

If it bootstraps successfully it will tell you as much, and then you can start the application:

sudo ./launcher start bava

If that works, you need to remember to restart Nginx using the command below:

Discourse 11

service nginx restart

We talked about mapping an A-record above, well if you haven’t done that your Discourse application won’t be visible anywhere. So, this might be a good time to go to the DNS Zone editor for the domain you want this to point to and add the IP address of the server to an A-record. It should look something like this:

Discourse 6After that, you should have a brand spanking new discourse application up and running. I still have yet to play with discourse., so that should be a future post.

Discourse 10

What’s cool is that if I run the docker ps command in terminal, I can see all the containers running discourse.

Screen Shot 2015-08-01 at 10.19.15 PM

If we could automate this process, which I imagine is possible, we could have a server that provides discourse instances for anyone that wants one. Making hosting an application like this relatively easy. And, unlike shared hosting or a multi-site application, the fact that it’s in a container means it would not effect any of the others. Trippy and cool.

Update 8/22/2017: I returned to this tutorial a couple weeks ago and realized I left one thing out. You need to change the email address at the bottom of the .yml file:

  ## If you want to set the 'From' email address for your first registration, uncomment and change:
  - exec: rails r "SiteSetting.notification_email='noreply@'"
  ## After getting the first signup email, re-comment the line. It only needs to run once.

I missed this and the user I created was not getting the confirmation email when trying to create the admin account. Surprise, surprise 🙂

This entry was posted in reclaim, Uncategorized and tagged , , , . Bookmark the permalink.

2 Responses to Discourse(s) on Docker

  1. Pingback: Restarting a Discourse Container | bavatuesdays

  2. Pingback: Discourse in the Reclaim Cloud | bavatuesdays

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.