mongo-provision
Create multi-node MongoDB clusters quickly & easily. Ideal for testing.
10K+
This tool provisions a MongoDB cluster for testing. All nodes of the cluster run in a single container.
# Start a 3-node replica set:
docker run -it --rm -p27017-27019:27017-27019 felipegasper298/mongo-provision 8.0 --replicaset --nodes 3
# … or, for a sharded cluster:
docker run -it --rm -p27017:27017 felipegasper298/mongo-provision 8.0 --replicaset --sharded 3 --nodes 3
The above will hang indefinitely until you kill it, e.g., via CTRL-C.
Then, in another terminal, run:
# for the replset:
mongosh mongodb://localhost:27017,localhost:27018,localhost:27019
# … or, for sharded:
mongosh mongodb://localhost:27017
… and you’re in!
Build the container:
docker build . -t mongo-provision
… then it’s the same as the above but with a local mongo-provision image
instead of felipegasper298/mongo-provision.
The arguments to the container are:
This container stores its state (e.g., mongod data files) under /data.
To introspect that state outside the container, mount a volume to that path
in the container.
The container will, on startup, check whether /data/bin/mongod exists. If it
does, and if its version matches the one given in the container’s
arguments, that binary will be used rather than downloading a new one.
If the supplied binary’s version mismatches the container’s arguments, the container will exit in error.
To use pre-downloaded binaries to start a sharded cluster, provide
both /data/bin/mongod and /data/bin/mongos. (The given mongos must match
its mongod.)
To check whether the cluster is ready, exec into the container and check if the
ready file exists. For example:
while ! docker exec my-container-name [ -e ready ]; do
echo "Still waiting for cluster to be ready …"
sleep 1
done
The ready file is a JSON file with the following data points:
connection_string (mongoses for sharded clusters)shards: a dictionary of shard name to connection string--platform linux/amd64 on multi-platform container engines.)This uses:
Content type
Image
Digest
sha256:5160758e1…
Size
255.2 MB
Last updated
4 months ago
docker pull felipegasper298/mongo-provision:v5