This guide describes how to run Rocket.Chat from this repository against a MongoDB instance you manage yourself (on another host, MongoDB Atlas, a managed service, and so on), instead of the bundled MongoDB in compose.database.yml.
Note: With external components used, our monitoring stack will not be able to scrape metrics from those services. Read ./external-service-metrics.md for more information.
-
Replica set
Rocket.Chat expects a MongoDB replica set. Your external cluster must be initialized as a replica set (even a single-node replica set is valid). The default connection string in this stack usesreplicaSet=rs0; your replica set name must match what you put inMONGO_URL. -
Database and access
Create a database user with permissions appropriate for Rocket.Chat, and note the authentication database (authSource) if it is not the default. -
Network reachability
Therocketchatcontainer must be able to reach every MongoDB host and port in your connection string (including replica set members). Open firewalls and security groups accordingly.
Copy .env.example to .env if you have not already, then set MONGO_URL: the full MongoDB connection URI for Rocket.Chat when you are not using the bundled MongoDB.
Standard replica set (single URI with options):
MONGO_URL=mongodb://USERNAME:PASSWORD@mongo1.example.com:27017,mongo2.example.com:27017/rocketchat?replicaSet=rs0&authSource=adminMongoDB Atlas (mongodb+srv):
MONGO_URL=mongodb+srv://USERNAME:PASSWORD@cluster0.xxxxx.mongodb.net/rocketchat?retryWrites=true&w=majorityAtlas and other SRV-based URLs are treated specially by the Rocket.Chat entrypoint in compose.yml: the container skips the TCP wait loop and starts the app immediately, because SRV resolution is not handled by the same nc check used for mongodb:// URLs.
MongoDB on the Docker host (Linux):
The hostname mongodb in the default stack refers to the bundled container. From inside another container, use the host’s IP, a DNS name, or Docker’s host gateway, for example:
MONGO_URL=mongodb://user:pass@172.17.0.1:27017/rocketchat?replicaSet=rs0&authSource=adminOr add extra_hosts in an override so host.docker.internal resolves (pattern depends on your Docker version).
Ensure replicaSet and authSource (and TLS options if you use TLS) match your deployment.
The README full stack includes compose.database.yml for bundled MongoDB. For external MongoDB, omit compose.database.yml and keep compose.nats.yml so the bundled NATS and nats-exporter still run (unless you also use external NATS):
docker compose \
-f compose.monitoring.yml \
-f compose.traefik.yml \
-f compose.yml \
-f compose.nats.yml \
-f docker.yml \
up -dIf you used Podman, replace docker compose with podman compose and include podman.yml or podman-rootful.yml as in the README.
- Prometheus / Grafana: File-based discovery includes
mongodb-exporter. If you no longer runmongodb-exporterfrom this stack, adjust Prometheus scrape configuration if you rely on those metrics. - Variables in
.env.examplesuch asMONGODB_BIND_IPandMONGODB_PORT_NUMBERapply to the bundled MongoDB service; they do not configure an external server.