RocketChat Update - Installing RocketChat with Docker and Docker Compose and Make it Publicly Available
This is part 1 of a few videos I'll be posting on RocketChat. It's an amazing system that competes with Slack, Teams, and so many other closed source online chat options. This project has been around for years now, and is very mature, and still going strong as far as continued development.
I will be posting some follow up parts that will focus on customizing (white labeling) RocketChat, and a separate video on adding your FreeIPA / LDAP authentication to RocketChat.
For now, let's get RocketChat installed, setup, and publicly accessible.
Installing Docker and Docker-Compose
We will be using Docker and Docker-Compose to install and setup RocketChat. If you don't have Docker and Docker-Compose installed, not to worry. I have posts with those instructions and how to's already, as well as a video on how to install Docker, Docker-Compose, and NGinX Proxy Manager, which will also use on this tutorial.
I make a script to install both Docker and Docker-Compose. You can create a file called "install_docker.sh" and paste the code below into it.
#!/bin/bash
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
## for ubuntu 18.04
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
## for ubuntu 20.04
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
sudo apt update
apt-cache policy docker-ce
sudo apt install docker-ce -y
## now set user as part of docker group
sudo usermod -aG docker ${USER}
## install docker-compose
sudo apt install docker-compose -y
Copy the text above into a new file. Take the 18.04, or 20.04 line based on the version of Ubuntu you are using.
Then save the file as docker_install.sh
.
This will make it simpler if you are setting up multiple physical servers or machines that you want to run docker on.
Install Rocketchat
On the machine where you've installed Docker and Docker-Compose, you want to create a new folder called RocketChat, or something similar:
mkdir rocketchat
Move into that folder, and create a new file called docker-compose.yml:
cd rocketchat
nano docker-compose.yml
We want to paste the following code into this file.
version: '2'
services:
rocketchat:
image: rocketchat/rocket.chat:latest
command: >
bash -c
"for i in `seq 1 30`; do
node main.js &&
s=$$? && break || s=$$?;
echo \"Tried $$i times. Waiting 5 secs...\";
sleep 5;
done; (exit $$s)"
restart: unless-stopped
volumes:
- ./uploads:/app/uploads
environment:
- PORT=3000
- ROOT_URL=http://localhost:3000
- MONGO_URL=mongodb://mongo:27017/rocketchat
- MONGO_OPLOG_URL=mongodb://mongo:27017/local
- MAIL_URL=smtp://smtp.email
# - HTTP_PROXY=http://proxy.domain.com
# - HTTPS_PROXY=http://proxy.domain.com
depends_on:
- mongo
ports:
- 3000:3000
mongo:
image: mongo:4.0
restart: unless-stopped
volumes:
- ./data/db:/data/db
#- ./data/dump:/dump
command: mongod --smallfiles --oplogSize 128 --replSet rs0 --storageEngine=mmapv1
# this container's job is just run the command to initialize the replica set.
# it will run the command and remove himself (it will not stay running)
mongo-init-replica:
image: mongo:4.0
command: >
bash -c
"for i in `seq 1 30`; do
mongo mongo/rocketchat --eval \"
rs.initiate({
_id: 'rs0',
members: [ { _id: 0, host: 'localhost:27017' } ]})\" &&
s=$$? && break || s=$$?;
echo \"Tried $$i times. Waiting 5 secs...\";
sleep 5;
done; (exit $$s)"
depends_on:
- mongo
The only line I changed from the official compose file is in the ports
section. I changed the left side of the colon ":" from 3000 to be 9201 because I know that port 3000 on my host is already in use. So in my file it looks like:
ports:
- 9201:3000
Once you have your file set, use CTRL + O
to save, press Enter / Return to confirm the use of the filename docker-compose.yml, then press CTRL + X
to exit the nano editor.
Now we'll startup our RocketChat instance with the command:
docker-compose up -d
This will begin the pull down of the images we need, and start the containers we need to run.
When it shows "done", go to the IP address of your host machine and the port you set on the left side of the colon in the docker-compose.yml file.
For me, I went to http://192.168.7.125:9201
First Run Wizard
When you visit the page, you'll be greeted by the First Run Wizard which will guide you through setting up your initial / admin account, and a few other things to make your RocketChat install your own.
WARNING: You may run into an issue where you fill out the first page of the wizard, click 'Continue', and it seems to be stuck.
Not to wory. Here's how you work around that. Open a new incognito / private window for your browser, and navigate to the IP address and port for your install in that window.
You'll be prompted to login. Use the email addreess (not the username) you created on page 1 of the wizard, and the password you created, and login.
From here, you should be taken to the next page of the wizard, and should be able to continue, and complete the setup.
Make a URL and get an SSL Certificate for your Install
Now, you'll need NGinX Proxy Manager setup and ready (that was part of the Video I linked above for "Putting It All Together".
In NGinX Proxy Manager, add a new Host entry.
Give it the name of your desired URL. NOTE: You must own the domain you use, and should point the A-Record in DNS for the subdomain / domain you want to use at your public IP address (home, vps, whatever that is).
I created chat.osia.me
and pointed the A-record at my Home Public IP.
I entered that url into my Host entry screen, and pressed Return to confirm it.
Next, makde sure you enter the IP address of the docker gateway for the RocketChat App container. To get this, you can do the following:
docker network ls
Find the network for rocketchat.
Now use,
docker network inspect <rocket chat network name>
Find the RocketChat App section, and look for the gateway IP address. Mine was 172.29.0.1
.
When you find yours enter it in the IP field of the host entry.
Now enter the port you set in the docker-compose file.
Enable the options for Block Common Exploits, and Websocket Support, and click 'Save'.
Make sure you can get to your RocketChat site with the URL via http only first. A test run.
If all goes well, you should be taken to the login page.
Now, let's get an SSL certificate.
Edit your host entry, and move to the SSL tab.
Select the 'Request a New Certificate' option from the dropdown, enable the Force SSL and HSTS options, enter your actual email address, and enable the 'Accept Terms of Service' option.
Click Save.
You should see the dialogue close, and have no errors if everything works.
Now, go to your URL again, and you should be automatically taken tot he SSL encrypted site to login.
I hope this guide is helpful to you, and you can feel free to reach out ot me at https://chat.osia.me and look for @MickInTx.