This is a simplistic project just to show how one can run the MongoDB with Replica Set turned on. It sounds trivial but many are struggling to do that when running only one instance, usually during the development process.
💡 docker-compose.yaml based - this runs the MongoDB using standard docker-compose
configuration.
docker-compose up -d
💡 Dockerfile based - this runs the MongoDB configured via the Dockerfile.
This is for those who would like to run single-node replica set using plain docker
instead of docker-compose
.
The whole configuration / scripts are moved from the docker-compose.yaml to the Dockerfile.
docker build . -t mogno-rs0-image
docker run -d mogno-rs0-image
When the MongoDB container starts it runs the script 2-init-replica-set.sh. The script is responsible for initiating the replica set mode through the execution of the followin command on the mongo instace:
rs.initiate()
You can read that procedure in the MongoDB documentation. However, the procedure is manual. Meaning one have to connect to the mongod
using mongosh
tool and execute the rs.initiate()
manually.
The 2-init-replica-set.sh script executes exactly that command but automatically, during the container initialization phase.
👍 Like it
🌠 Star it
📥 Take it