Rocket.Chat icon indicating copy to clipboard operation
Rocket.Chat copied to clipboard

How to use docker-compose scale services

Open zahaim opened this issue 10 years ago • 9 comments

Your Rocket.Chat version: 0.44.0, Docker version 1.10.3, Docker-compose 1.8.0

I created docker-compose version '2' file so I could scale the service with: docker-compose scale rocketchat=3 This seems to be reasonable as node.js apps use only 1 core so I wanted to have 3 of them running on 1 host.

Rocketchat declaration looks like this:

version: '2'
services:
  rocketchat:
    image: rocketchat/rocket.chat:latest
    volumes:
      - ./uploads:/app/uploads
    environment:
      - PORT=3000
      # set FQDN here
      - ROOT_URL=https://${ROCKETCHAT_URL}
      - MONGO_URL=mongodb://mongo:27017/rocketchat
      - MONGO_OPLOG_URL=mongodb://mongo:27017/local
    networks:
      - front-tier
      - back-tier

The thing is, that as described in #4525 the instances are not synced. I know that the solution was to use INSTANCE_IP= but here it is not possible. Rocketchat container is declared one single time in docker-compose.yml file and then scaled as a service.

Any ideas?

zahaim avatar Oct 26 '16 12:10 zahaim

salamachinas avatar Jan 12 '17 08:01 salamachinas

@rodrigok is the documentation for this ready?

engelgabriel avatar Jan 19 '17 19:01 engelgabriel

@zahaim a nice little trick you can use is to a command field like this:

command: /bin/sh -c 'INSTANCE_IP=$$(hostname -i) node main.js'

This sets the INSTANCE_IP right before starting rocket.chat.

geekgonecrazy avatar May 08 '17 23:05 geekgonecrazy

Hi @geekgonecrazy I added the command you mentioned in my docker-compose.yml and it worked like a charm! This makes scaling rocketchat easy with docker-compose / swarm mode. Thanks!

zahaim avatar May 10 '17 09:05 zahaim

@zahaim you'll wanna change that to a lower case i in the command. hostname -I includes a space after it breaking interconnect. hostname -i does not.

I edited above so anyone else that comes across will use the correct one

geekgonecrazy avatar May 11 '17 18:05 geekgonecrazy

@geekgonecrazy yeah, I figured it out. Still, many thanks for the idea.

I knew before that setting up INSTANCE_IP as a variable was a solution but I was sure that it was also needed to add the array of all instances like:

extra_hosts:
    - "rocket-1:10.250.250.13"
    - "rocket-2:10.250.250.14"
    - "rocket-3:10.250.250.17"

But, as far as I can see this is not necesary so your solution works perfect. I only struggle with File Uploads now but I guess the reason is that I mount the same fs to many containers. I will check if nfs is an option.

zahaim avatar May 12 '17 08:05 zahaim

@zahaim if you are using Gridfs or filesystem check out #6926

Basically if on same server you can mount /tmp to all containers. If not on same server until that bug is fixed... You'll need to use something like Minio or another block store

geekgonecrazy avatar May 12 '17 15:05 geekgonecrazy

@geekgonecrazy - yep, this is the case for me. I used your workaround (thanks) as I have it on 1 server. I will follow the other issue before switching to swarm.

zahaim avatar May 15 '17 07:05 zahaim

GlusterFS + Docker Storage Plugin "local-perist" did it for me on a multi-node swarm cluster.

Berndinox avatar Aug 17 '17 12:08 Berndinox