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:

 

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 ten copy another installs config and change a few details.  So, edit another YAML file by typing something like this:

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

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:

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:

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 bit difference from applications in a LAMP environment which has 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.

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 exampled, if I copy and pasted from the reclaim.yml file, everywhere you see bava below would have originally been reclaim

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

Got to:

From there you need to edit the discourse file:

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.bavatuesdays.com) as well as putting bava in the proxy_pass file path:

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.

Discourse 8

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

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

Discourse 11

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.bavatuesdays.com, 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 is 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:

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.

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.