/ Docker

Setup RocketChat on Docker Swarm with Traefik Reverse Proxy

Rocket Chat is a Great Self-Hosted Open Source Communication Platform for Teams and Communities.

You can almost categorize it as a Open Source Self Hosted Slack-like Platform.

Features:

Rocket Chat offers features such as:

What we will be doing today:

Today, we will setup Rocket Chat on Docker Swarm.

Pre-Requirements:

Once you have the pre-requirements setup, we can move onto the next step.

Using Traefik as the Reverse Proxy:

We will setup Traefik as our Reverse Proxy with Letsencrypt for SSL Termination, do in order to do that, we will need to build our image and push it to your registry of choice:

Our Traefik Dockerfile:

FROM traefik
ADD traefik.toml .
EXPOSE 80
EXPOSE 8080
EXPOSE 443

Our traefik.toml:

defaultEntryPoints = ["http", "https"]

[web]
address = ":8080"

[entryPoints]

[entryPoints.http]
address = ":80"

[entryPoints.https]
address = ":443"

[entryPoints.https.tls]

[acme]
email = "recipient@domain.com"
storage = "acme.json"
entryPoint = "https"
onDemand = false
OnHostRule = true

[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "apps.domain.com"
watch = true
exposedbydefault = false

I personally use gitlab's private registry for my docker images, so I will build and push it to gitlab:

$ docker login registry.gitlab.com
$ docker build -t registry.gitlab.com/<user>/<repo>/traefik:latest .
$ docker push registry.gitlab.com/<user>/<repo>/traefik:latest

Creating the Traefik Service:

Create the Overlay Network:

$ docker network create appnet --driver overlay

Create the Traefik Service:

$ docker service create \
--name traefik \
--constraint 'node.role==manager' \
--publish 80:80 \
--publish 443:443 \
--publish 8080:8080 \
--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \
--network appnet \
--with-registry-auth registry.gitlab.com/<user>/<repo>/traefik:latest \
--docker \
--docker.swarmmode \
--docker.domain=apps.domain.com \
--docker.watch \
--logLevel=DEBUG \
--web

Create the Rocket Chat Service:

For the current scenarion we have the following envionment:

  • MongoDB URi: "mongodb://mongoadmin:mongopass@db.domain.com:27017/rocketchat?authSource=admin"
  • Rocket Chat URL: "https://apps.domain.com"
  • Rocket Chat Admin User, Pass, Email

Create the Rocket Chat Service:

$ docker service create \
--name rocketchat \
--replicas 1 \
--network appnet \
--label 'traefik.port=3000' \
--label traefik.frontend.rule="Host:apps.domain.com" \
--env DEPLOY_METHOD=docker \
--env NODE_ENV=production \
--env PORT=3000 \
--env MONGO_URL="mongodb://mongoadmin:mongopass@mdb.domain.com:27017/rocketchat?authSource=admin" \
--env ROOT_URL=https://aps.domain.com \
--env ADMIN_USERNAME=myadmin \
--env ADMIN_PASS=secret \
--env ADMIN_EMAIL=mail@domain.com \
--env Accounts_AvatarStorePath=/app/uploads \
--secret rocketchat_secret \
rocketchat/rocket.chat

Once your services has reached its desired state, you should be able to access Rocket Chat on the chosen URL.

Setup Mail:

In order to invite users, make sure to configure your mail settings, which can be found from Administration -> Email -> SMTP.

Setup a Giphy Bot in Rocket Chat:

A cool integration is to setup a bot that uses the Giphy API to send gifs with your conversations. A setup guide shows you how to get that setup.

Setup a Telegram Bot for Rocket Chat:

Use the Incoming and Outgoing Webhooks to setup a Simple Telegram Bot, a full setup guide shows you how to get that done, which is really cool.

Custom Emoji's:

Let's face it, we all love emoji's. Head over to slackemojis and download your favorite emoji's, then head over to Rocket Chat: Administration -> Custom Emoji to import them.

Using the API via Python:

In a later post, I will give some example code on how to use Python to use Rocket Chat's API to send messages to Channels and Users, but for now, you can find the documentation for rocket-python here

Join Us:

Feel free to join my RocketChat Server, it's quite fresh, so nothing much is going on in there, but the idea is to share awesome posts, new findings, playing around with its API and knowledge sharing.

I hope this is useful, please leave a comment below if you theres any questions.