MongoDB with replica set and healthcheck out of the box. Node.js, Mongoose, Docker Compose ready.
2.6K
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-rs
docker compose up -d
Example 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:
rs.initiate() on first run, no manual setupdepends_on: condition: service_healthyMONGO_RS, MONGO_USER, MONGO_PASSWORD, MONGO_AUTHDBMONGO_PASSWORD_FILE for Docker secrets / KubernetesfeatureCompatibilityVersion aligned 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 — iddqd is for dev only
Use secrets — MONGO_PASSWORD_FILE with 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.sh
mongo-rs is free, open-source, and maintained by one developer.
If it saves you time or improves your MongoDB replica set setup:
GitHub • See CONTRIBUTING.md
Content type
Image
Digest
sha256:1bd9ec348…
Size
313.8 MB
Last updated
8 months ago
docker pull nesvet/mongo-rs