This repository need you run a few commands to set up replica set and it uses docker compose to launch the replica set. The docker compose file will deploy 3 separate containers:
- mongo1
- set as primary with priority 7
- map container port
27017
to localhost27021
- mongo2
- mongo3
All container are using one internal network so that them can connect to each other. Also they use same mongod.cfg and enabled key file authentication.
- Build up all containers
docker compose up -d --build
- Run script in mongo1 terminal. The script will initialize replica configuration and create a root user. This script may cost 30 seconds, because it need to wait node to become primary
/config/init.sh
- Access mongodb with url:
mongodb://tom-rs:jerry@localhost:27021/?directConnection=true&authMechanism=DEFAULT