How To Install Rocketchat on Ubuntu 16.04 Using Docker & Docker Compose

1. Install Docker

see How To Install Docker On Ubuntu 16.04

2. Install Docker Compose

see How to Install Docker Compose on Linux Systems

3. Creating the docker-compose file

First, we create a space for our docker-compose.yml file. We will place this in our user’s home directory:

$ cd ~
$ mkdir rocket.chat && cd rocket.chat

Next, create a docker-compose.yml file to tell Docker how you want the system configured:

$ sudo nano docker-compose.yml

Copy/paste the code below example file from Rocketchat. You will need to change a few of the variables to fit your unique installation.

Find line 11 of the docker-compose.yml file, which begins with ROOT_URL. You will need to change the ROOT_URL based on your particular needs. If you’d like to host Rocketchat on yourdomain.com, or even chat.yourdomain.com, replace localhost:3000 with that and be sure to have your DNS set up properly. If you want to use your VPS’ public IP to connect to Rocketchat, replace localhost:3000 with that IP. If you fail to specify the protocol (http) or the port (:3000, but only if you’re using one), the installation won’t work.

version: '2'

services:
  rocketchat:
    image: rocketchat/rocket.chat:latest
    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
    labels:
      - "traefik.backend=rocketchat"
      - "traefik.frontend.rule=Host: your.domain.tld"

  mongo:
    image: mongo:3.2
    restart: unless-stopped
    volumes:
     - ./data/db:/data/db
     #- ./data/dump:/dump
    command: mongod --smallfiles --oplogSize 128 --replSet rs0
    labels:
      - "traefik.enable=false"

  # 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:3.2
    command: 'mongo mongo/rocketchat --eval "rs.initiate({ _id: ''rs0'', members: [ { _id: 0, host: ''localhost:27017'' } ]})"'
    depends_on:
      - mongo

  # hubot, the popular chatbot (add the bot user first and change the password before starting this image)
  hubot:
    image: rocketchat/hubot-rocketchat:latest
    restart: unless-stopped
    environment:
      - ROCKETCHAT_URL=rocketchat:3000
      - ROCKETCHAT_ROOM=GENERAL
      - ROCKETCHAT_USER=bot
      - ROCKETCHAT_PASSWORD=botpassword
      - BOT_NAME=bot
  # you can add more scripts as you'd like here, they need to be installable by npm
      - EXTERNAL_SCRIPTS=hubot-help,hubot-seen,hubot-links,hubot-diagnostics
    depends_on:
      - rocketchat
    labels:
      - "traefik.enable=false"
    volumes:
      - ./scripts:/home/hubot/scripts
  # this is used to expose the hubot port for notifications on the host on port 3001, e.g. for hubot-jenkins-notifier
    ports:
      - 3001:8080

  #traefik:
  #  image: traefik:latest
  #  restart: unless-stopped
  #  command: traefik --docker --acme=true --acme.domains='your.domain.tld' --acme.email='your@email.tld' --acme.entrypoint=https --acme.storagefile=acme.json --defaultentrypoints=http --defaultentrypoints=https --entryPoints='Name:http Address::80 Redirect.EntryPoint:https' --entryPoints='Name:https Address::443 TLS.Certificates:'
  #  ports:
  #    - 80:80
  #    - 443:443
  #  volumes:
  #    - /var/run/docker.sock:/var/run/docker.sock

4. Starting MongoDB

We need to start up mongo before you can launch Rocket.Chat:

$ docker-compose up -d mongo

Check that mongo has started properly by listing the running Docker containers:

$ docker ps

You should see output similar to below:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                      NAMES
428c285d6df9        mongo:3.2           "docker-entrypoint.s…"   2 minutes ago       Up 2 minutes        27017/tcp                  rocketchat_mongo_1

Initialize the database:

$ docker-compose up -d mongo-init-replica

5. Start Rocketchat

Launch Rocketchat:

$ docker-compose up -d rocketchat

Check docker ps to make sure Rocketchat is running:

$ docker ps

You should see output similar to below:

CONTAINER ID        IMAGE                           COMMAND                  CREATED              STATUS              PORTS                      NAMES
50624621e8d8        rocketchat/rocket.chat:latest   "node main.js"           About a minute ago   Up About a minute   0.0.0.0:3000->3000/tcp     rocketchat_rocketchat_1
428c285d6df9        mongo:3.2                       "docker-entrypoint.s…"   7 minutes ago        Up 7 minutes        27017/tcp                  rocketchat_mongo_1

Open your browser to the url you specificied in ROOT_URL of the docker-compose.yml file


ERRORS & SOLUTIONS

Can’t connect to url specificed in ROOT_URL
https://rocket.chat/docs/installation/docker-containers/
I can only connect via the ip address of the server with port 3000 (e.g. 123.456.789.1:3000).

1. Edit the hosts file

$ sudo nano /etc/hosts

Add your url after localhost:

127.0.0.1    localhost.localdomain    localhost
127.0.0.1    chat.mydomain.com         chat

2. Edit the Nginx server block configured

You can just add this to the bottom of your default server block. Change (1) server_name, (2) ssl_certificate and ssl_certificate_key locations (you may not need the rest of the ssl code) and (3) proxy_pass url (but keep port 3000). :

server {
        listen 443 ssl;
        server_name chat.mydomain.com;

        error_log /var/log/nginx/rocketchat_error.log;

        ssl_certificate /etc/nginx/certificate.crt;
        ssl_certificate_key /etc/nginx/certificate.key;
        ssl_dhparam /etc/nginx/dhparams.pem;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:20m;
        ssl_session_timeout 180m;

        location / {
            proxy_pass http://chat.mydomain.com:3000/;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forward-Proto http;
            proxy_set_header X-Nginx-Proxy true;
            proxy_redirect off;
        }
    }

Now open your browser to the url you specificied in ROOT_URL of the docker-compose.yml file

REFERENCES

https://blog.ssdnodes.com/blog/tutorial-installing-slack-alternative-rocket-chat-with-docker/
https://rocket.chat/docs/installation/docker-containers/docker-compose/
https://rocket.chat/docs/installation/docker-containers/
https://raw.githubusercontent.com/RocketChat/Rocket.Chat/develop/docker-compose.yml

2 thoughts on “How To Install Rocketchat on Ubuntu 16.04 Using Docker & Docker Compose

  1. Thank you. But can you give me an idea which folder(s) are necessary for a backup of the chat data? Because of the docker installation we can’t find out, which files we have to backup.
    Thank in advance.

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.