Mongo replication set with four nodes, run and start with docker compose:
sudo mkdir -p -m 777 mongo/primary
sudo chown -R 1001 mongo
NOTE: As this is a non-root container, the mounted files and directories must have the proper permissions for the UID 1001.
docker-compose up -d
NOTE: It will take time to initiate for first time
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
127.0.0.1 mongodb-arbiter
mongodb://root:password123@mongodb-primary:27017,mongodb-secondary-1:27018,mongodb-secondary-2:27019,mongodb-arbiter:27020/?replicaSet=rs0&authSource=admin