Your app needs a replica set — Node.js driver, Mongoose, Change Streams, transactions all require it. The official mongo image runs standalone; mongo-rs extends it with a replica set on first run. One container, no init scripts.
docker run -d -e MONGO_PASSWORD=secret nesvet/mongo-rsdocker compose up -dExample with app service:
services:
mongo:
image: nesvet/mongo-rs
environment:
MONGO_PASSWORD: ${MONGO_PASSWORD:-secret}
volumes:
- mongo-data:/data/db
restart: unless-stopped
app:
image: myapp:latest
environment:
MONGO_URI: mongodb://root:${MONGO_PASSWORD:-secret}@mongo:27017/?directConnection=true
depends_on:
mongo:
condition: service_healthy
volumes:
mongo-data:- Auto-init replica set —
rs.initiate()on first run, no manual setup - Built-in healthcheck — 15s interval, ready for
depends_on: condition: service_healthy - Env-based config —
MONGO_RS,MONGO_USER,MONGO_PASSWORD,MONGO_AUTHDB - Secrets support —
MONGO_PASSWORD_FILEfor Docker secrets / Kubernetes - FCV auto-update —
featureCompatibilityVersionaligned with MongoDB version
→ Local dev with Node.js / Mongoose
No more MongoServerSelectionError: connection refused. Your driver expects a replica set; mongo-rs provides one.
→ Docker Compose with depends_on
Healthcheck built in. depends_on works out of the box.
→ Same setup dev → prod
Single node locally, add nodes in production. Same connection string format, no code changes.
| Variable | Default | Description |
|---|---|---|
MONGO_RS |
rs0 |
Replica set name |
MONGO_AUTHDB |
admin |
Authentication database |
MONGO_USER |
root |
Admin username |
MONGO_PASSWORD |
iddqd |
Admin password |
MONGO_PASSWORD_FILE |
— | Path to file with password (Docker secrets) |
Connection string (single-node, use directConnection=true): options
mongodb://root:${MONGO_PASSWORD}@mongo:27017/?directConnection=true
-
Change default password —
iddqdis for dev only -
Use secrets —
MONGO_PASSWORD_FILEwith Docker secrets or an external secret manager:services: mongo: image: nesvet/mongo-rs environment: MONGO_PASSWORD_FILE: /run/secrets/mongo_password secrets: - mongo_password volumes: - mongo-data:/data/db restart: unless-stopped secrets: mongo_password: file: ./secrets/mongo_password.txt volumes: mongo-data:
-
See SECURITY.md for vulnerability reporting
./test.shmongo-rs is free, open-source, and maintained by one developer.
If it saves you time or improves your MongoDB replica set setup:
- ⭐ Star the repo — it helps discoverability
- 💙 Support on Patreon — priority features & long-term maintenance
See CONTRIBUTING.md