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 && cd

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, or even, 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'

    image: rocketchat/
    restart: unless-stopped
      - ./uploads:/app/uploads
      - PORT=3000
      - ROOT_URL=http://localhost:3000
      - MONGO_URL=mongodb://mongo:27017/rocketchat
      - MONGO_OPLOG_URL=mongodb://mongo:27017/local
      - MAIL_URL=smtp://
#       - HTTP_PROXY=
#       - HTTPS_PROXY=
      - mongo
      - 3000:3000
      - "traefik.backend=rocketchat"
      - "traefik.frontend.rule=Host: your.domain.tld"

    image: mongo:3.2
    restart: unless-stopped
     - ./data/db:/data/db
     #- ./data/dump:/dump
    command: mongod --smallfiles --oplogSize 128 --replSet rs0
      - "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)
    image: mongo:3.2
    command: 'mongo mongo/rocketchat --eval "rs.initiate({ _id: ''rs0'', members: [ { _id: 0, host: ''localhost:27017'' } ]})"'
      - mongo

  # hubot, the popular chatbot (add the bot user first and change the password before starting this image)
    image: rocketchat/hubot-rocketchat:latest
    restart: unless-stopped
      - ROCKETCHAT_URL=rocketchat:3000
      - 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
      - rocketchat
      - "traefik.enable=false"
      - ./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
      - 3001:8080

  #  image: traefik:latest
  #  restart: unless-stopped
  #  command: traefik --docker --acme=true'your.domain.tld''[email protected]' --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/   "node main.js"           About a minute ago   Up About a minute>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


Can't connect to url specificed in ROOT_URL
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:    localhost.localdomain    localhost         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;

        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_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:20m;
        ssl_session_timeout 180m;

        location / {
            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


3 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.

  2. Hello I followed all steps but my rocket chat docker restarting.

    a3c349c776b3 rocketchat/ “docker-entrypoint.s…” 22 minutes ago Restarting (1) 6 seconds ago rocketchat_rocketchat_1

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.