MongoDB Replica set version-docker

Source: Internet
Author: User
Tags mongo shell docker run

1. Host and container planning
Docker host Container name Port Replica set
192.168.0.40 M40 27017 Rs0
192.168.0.41 M41 27017 Rs0
192.168.0.42 M42 27017 Rs0
2. Create container 2.1 to create a container on host 40 M40
docker run     --name m40                                 -d                                         -p 27017:27017                             -v /etc/localtime:/etc/localtime:ro        -v /data/db:/data/db                       -v /data/configdb:/data/configdb           reg.citms.cn/public/mongo:3.2.19           mongod --replSet rs0
2.2. Create a container on host 41 M41
docker run     --name m41                                -d                                        -p 27017:27017                            -v /etc/localtime:/etc/localtime:ro       -v /data/db:/data/db                      -v /data/configdb:/data/configdb          reg.citms.cn/public/mongo:3.2.19          mongod --replSet rs0
2.3. Create a container on host 42 M42
docker run     --name m42                                -d                                        -p 27017:27017                            -v /etc/localtime:/etc/localtime:ro       -v /data/db:/data/db                      -v /data/configdb:/data/configdb          reg.citms.cn/public/mongo:3.2.19          mongod --replSet rs0
3. Build a replica set

# # #3.1. Connect one of the containers and run the MONGO shell

docker exec -it m40 mongo

# # #3.2. Initialize replica set

rs.initiate( {   _id : "rs0",   members: [      { _id: 0, host: "192.168.0.40:27017" },      { _id: 1, host: "192.168.0.41:27017" },      { _id: 2, host: "192.168.0.42:27017" }   ]})

# # #3.3. View replica set configuration, output slightly

rs.conf()

# # #3.5. Identify the primary node of the replica set, the output is slightly

rs.status()

MongoDB Replica set version-docker

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.