This guide uses Docker Compose to run Rocket.Chat in containers with MongoDB replica set. Rocket.Chat requires MongoDB with replica set enabled for real-time updates.
For Docker installation, see Docker.
Create a docker-compose.yml file with the following content:
version: '3.8'
services:
rocketchat:
image: rocket.chat:latest
container_name: rocketchat
restart: unless-stopped
ports:
- "3000:3000"
environment:
- ROOT_URL=https://chat.example.com
- MONGO_URL=mongodb://db:27017/rocketchat
- MONGO_OPLOG_URL=mongodb://db:27017/local
- MAIL_URL=smtp://smtp.example.com:587
depends_on:
- db
volumes:
- ./uploads:/app/uploads
db:
image: mongo:8.0
container_name: rocketchat-db
restart: unless-stopped
command: mongod --replSet rs0 --oplogSize 128
volumes:
- ./dbdata:/data/db
environment:
- MONGO_INITDB_ROOT_USERNAME=rocketchat
- MONGO_INITDB_ROOT_PASSWORD=your-mongo-password
Security Note: Replace the following before deployment:
your-mongo-password - Strong MongoDB root passwordhttps://chat.example.com - Your Rocket.Chat server URLsmtp.example.com - Your SMTP server for email notificationsAfter starting the containers, you must initialize the MongoDB replica set:
# Wait for MongoDB to start
sleep 10
# Initialize replica set
docker compose exec db mongosh --username rocketchat --password your-mongo-password --eval "rs.initiate({_id: 'rs0', members: [{_id: 0, host: 'localhost:27017'}]})"
docker compose up -d
Wait for the containers to start (approximately 2-3 minutes for first run).
Open http://YOUR-SERVER:3000 to access Rocket.Chat.
On first access, you’ll be prompted to create an admin account.
For production deployments:
Add the MAIL_URL environment variable:
environment:
- MAIL_URL=smtp://username:password@smtp.example.com:587
For production, consider a 3-node MongoDB replica set:
services:
db1:
image: mongo:8.0
command: mongod --replSet rs0 --oplogSize 128
db2:
image: mongo:8.0
command: mongod --replSet rs0 --oplogSize 128
db3:
image: mongo:8.0
command: mongod --replSet rs0 --oplogSize 128
See Configuration and Security for production hardening.
Any questions?
Feel free to contact us. Find all contact information on our contact page.