Rocket.Chat - SLACK alternative (with MongoDB as backend)

Docker Rocket.Chat - SLACK alternative (with MongoDB as backend)

rocket_chat.jpg


Did you hear of SLACK? How about Discord? Microsoft Teams? Great! Then you know what this tutorial will be all about.

In this tutorial, we will focus on running an open source, private alternative to those platforms. Enter, Rocket.Chat

Just in case you haven't heard about any of those platforms or have never used them, let say in short what RC is. In short, RC is a platform that will allow you to run your very own, private chat platform by means of using private messages, public and private channels, E2E encryption (still in beta), and even voice and audio.
On top of all this, there are also options to send files, run separate discussions, links, and more. The platform can be accessed via a web UI, and any modern mobile or desktop OS. To conclude, considering that its open source you can customize it to your needs (CSS, logo, and fonts for example).

This platform will be run via Docker considering it's not supported natively via package center (Synology has its own version called Chat). We will need 2 things. MongoDB container and RC container.
In the past month, RC DEV team has made a change on the MongoDB side that got many users upset because the new version of RC (1.0+) would not run without the proper settings on the MongoDB instance. We will cover that part as well. Let's start.

01. MongoDB container

For this setup, we can use mongo:latest image configured with the following settings (I will not post docker compose file here considering some people might use the Synodocker UI):

Port: 27017
Volume:
/your/local/folder/mongodb:/data/db
/your/local/folder/mongodb/mongod.conf:/etc/mongod.conf

Environment variables (apart from the default ones):
MONGO_INITDB_DATABASE = db
MONGO_INITDB_ROOT_USERNAME = root
MONGO_INITDB_ROOT_PASSWORD = define a pass for your root account
IMPORTANT!
Be sure that you will enter the following command in the CMD parameter when creating this container! This can be set under the Environmental variable tab (Synology Docker UI on the bottom of the tab).

Code:
mongod --oplogSize 128 --replSet rs0

One more thing that needs to be configured for all this to work is to prepare the conf file (that will be mapped as a volume). Open up a text editor and create one with the following content:

Code:
replication:
    replSetName: "rs0"

After you have setup the container you will need to prepare it to run in replica mode. To do that connect to your container via a command line or the Terminal tab in Syno UI (or via portainer if you are running it) using the bash command.

Now 1st thing we need is an admin mongoDB database. The reason is that we will have to convert this mongoDB instance as the 1st replica node (no matter that there will be no other nodes in the future, this is how RC currently works, and demands the setting).

After you have started bash command inside the mongodb container (via Terminal tab for example). Run the following command:

Code:
mongo -u root -p yourRootPass --authenticationDatabase admin

Make sure that root password is the same one that you have used as an env variable parameter for the MONGO_INITDB_ROOT_PASSWORD variable

In case you run into a problem connecting to your mongo instance using the admin DB (previous step) make sure to try and create and admin user for the db databse. Run the following command:
db.createUser({user: "admin", pwd: "xxxxxxxx", roles: [{role: "readWrite", db: "db"}]})
Use your root password (the one from the environmental variable as a password

If you have managed to log as root your command line will be something like rs:PRIMARY or something like that.

Now comes that most important command line that will convert your mongoDB instance as a replica. Run this as a single-line command:

Code:
rs.initiate({ _id: 'rs0', members: [ { _id: 0, host: 'localhost:27017' } ]})

Make sure that rs# parameter is the same one as the one that you have entered in your conf file as well as the port number that needs to be the same as your mongoDB INTERNAL/container port. Not the port that will be visible on the host side.

With all that, we are done with mongoDB container. Damn! Let's move on.

02. Rocket.Chat container

RC image will be rocketchat/rocket.chat:latest that's the official image from RC team.

There are only several env variables that need to be configured. There are no volumes that this image use considering that all configuration and data parameters are stored on the mongoDB side.

PORT: 3000 (or some port of your choice)
LINKS: your mongoDB container > alias: db (or whatever you want)

Environment variables (apart from the default ones):
MONGO_URL = mongodb://root:yourRootPass@db:27017/db?authSource=admin&directConnection=true
MONGO_OPLOG_URL = mongodb://root:yourRootPass@db:27017/local?authSource=admin&directConnection=true

Keep in mind that db parameter after @ needs to be the same one as the one that you have used in the LINKS. Also, the port number needs to be the same one as INTERNAL/container parameter for your mongoDB
ROOT_URL = http://localhost:3000
Please note that there is no need to set the root url to a specific https fqdn considering that you can run this container via reverse proxy just like any other app. However, iOS app will have a problem with specific functions in that case. To avoid it, make sure that your ROOT_URL is the same as your public fqdn if you intend to publish this instance to the Internet.

PROBLEMS connecting RC to MongoDB
NOTE: if you run into the following problem, please log into your mongo instance using the method above and run the following commands. This error will be visible in the MongoDB container log! Also, this will probably result in an immediate crash of RC contianer upon start, so be sure to check the MongoDB side of things.

ERROR:
Authentication failed","attr":{"mechanism":"SCRAM-SHA-256","principalName":"MyUser","authenticationDatabase":"mydb","client":"127.0.0.1:2012","result":"UserNotFound: Could not find user \"MyUser\" for db \"mydb\""}}

In this case, run the following command:

db.createUser(
{
user: "MyUser",
pwd: "MyuserPassword",
roles: [ { role: "userAdminAnyDatabase", db: "mydb" } ]
}
)

Of course, MyUser can be also the root account and mydb can be the "admin" DB, but that will depend on the ERROR output. So change it accordingly!

That's it! Run the container and keep your eye on the log. If all is well you will see get a nice SERVER RUNNING message in your log.

Now all that's left is to access it on its custom 3000 port and start configuring your very own private chat platform!
  • 1560337165935.png
    1560337165935.png
    79.7 KB · Views: 1,449



Latest updates

  1. RC and Mongo docker-compose examples

    Rocket.Chat version: '3.1' services: rocketchat: image: rocketchat/rocket.chat:latest...
  2. Rocket.Chat push notification upcoming changes

    Here is a short article on the upcoming changes regarding support for push notification for...
  3. Rocket.Chat omnichannel (LiveChat) feature

    Just a short post on activating the Live Chat support feature via RC to give you more options...

Latest reviews

this is one of my most used container
Rusty
Rusty
It is nice isn't it? :D
Upvote 1
Back
Top