Sometimes you need a replica set in your local environment (perhaps you want to use the oplog). But it's somewhat involved to spin up a series of mongo containers and provide the correct configuration. This docker image will create a self-contained 3 node replica set (that is, all three nodes are running in one container).
THIS IS ONLY USEFUL FOR LOCAL DEVELOPMENT
You need to know the following:
User info is configured on the admin database:
dev
dev
Each instance exposes a port, all listening on 0.0.0.0 interface:
27001
[primary]27002
27003
The container will create one volume at /data
, but you can mount one or more to your host at these paths:
/data/db1
[primary]/data/db2
/data/db3
It's called: rs0
If you mount something into /data/db1
, the container will not go through it's initialization process, but it will also assume that you have mounted all 3 volumes -- so mount all 3 or none. You can customize the username/password by providing USERNAME
/PASSWORD
environment variables (but you probably don't need to).
docker run -d --name mongo -v $(pwd)/data:/data boucher/mongo-local-replicaset
mongodb://dev:dev@mongo:27001,mongo:27002,mongo:27003/db?authSource=admin