--replSet
)--replSet "my-set"
flag set for the daemon and keep the previous information intactI am trying to follow along a tutorial for setting replica sets in MongoDB with Docker and trying it out on my local machine.
Create a standard MongoDB Docker container w/o the flag replSet
set which represents the current state:
docker run -d --name mongo_rs --publish 37017:27017 mongo
Using the MongoDB Compass I connected to the DB and added some dummy information to a Database called test
and collection called players
I stop the container:
docker container stop mongo_rs
From here onwards I wish to add the --replSet "my-set"
to the mongo_rs
container and configuring the Replica set via the mongo
Shell as mentioned in the tutorial. What is the possible solution for achieving it?
Here is my .yml file
version: '3.7'
services:
node1:
image: mongo
ports:
- 30001:27017
volumes:
- $HOME/mongoclusterdata/node1:/data/db
networks:
- mongocluster
command: mongod --replSet comments
node2:
image: mongo
ports:
- 30002:27017
volumes:
- $HOME/mongoclusterdata/node2:/data/db
networks:
- mongocluster
command: mongod --replSet comments
depends_on :
- node1
node3:
image: mongo
ports:
- 30003:27017
volumes:
- $HOME/mongoclusterdata/node3:/data/db
networks:
- mongocluster
command: mongod --replSet comments
depends_on :
- node2
networks:
mongocluster:
driver: bridge
The volume section has absolute path which is different from the root.Actually docker file creates a self config file on root , so if u have root as a docker-compose install location change it to else where, and now the config file settings would never delete on docker-install up/down.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With