Install RocketChat with Docker Compose for Development

If you ask me: what the hell Rocketchat is, then you should better ask Google. This article notes steps to install RocketChat with Docker Compose for development purpose.

1. Create docker-compose.yml

I want to expose the mongo port (27017) to the host network so I also declare it in the ports param. I also map the default rocketchat port (3000) to port 4000 in the host since I am using port 3000 for another service.

version: "3"
services:
  mongo:
    image: mongo
    ports:
      - 27017:27017
    volumes:
      - ./data/runtime/db:/data/db
      - ./data/dump:/dump
    command: mongod --smallfiles --oplogSize 128
    networks:
      - rcnet
  rocketchat:
    image: rocketchat/rocket.chat:latest
    environment:
      - MONGO_URL=mongodb://mongo/rocketchat
      - ROOT_URL=http://chat.localhost
      - PORT=3000
    networks:
      - rcnet
    ports:
      - 4000:3000
    depends_on:
      - mongo
networks:
  rcnet:
    driver: bridge

 

2. Start services

It is worth noting that you need to start mongo and rocketchat sequentially. If you simply run docker-compose up, the rocketchat service cannot recognize mongo service is completely started, so it fails since there is no retry after that. Even if you put the depends info in the docker-compose.yml, it still fails. The following error will appear:

MongoError: failed to connect to server [mongo:27017] on first connect [MongoError: connect ECONNREFUSED 172.18.0.2:27017]

So, you should start mongo service first, and then start the rocketchat service as follows:

docker-compose up -d mongo
docker-compose up -d rocketchat

 

 

Leave a Reply