Prepare the data directory:
sudo mkdir -p -m 777 mongo/primary
sudo chown -R 1001 mongo
docker-compose up -d
Add this lines to /etc/hosts
:
127.0.0.1 mongodb-primary
127.0.0.1 mongodb-secondary-1
127.0.0.1 mongodb-secondary-2
mongodb://root:password123@localhost:27017,localhost:27018,localhost:27019/?replicaSet=rs0
docker exec -it mongodb-primary mongosh
Log into primary container
$ use admin
$ db.auth("root", "password123")
$ rs.status()
$ rs.conf()
Log into primary container
$ use admin
$ db.auth("root", "password123")
Change priority value of Primary instance to 5
$ cfg = rs.conf()
$ cfg.members[0].priority = 5
$ rs.reconfig(cfg)