Git Product home page Git Product logo

mongodb-replicaset-docker's Introduction

mongodb-replicaset-docker

Setup MongoDB in Docker Container With Replicaset

How to

Before doing step below, please configure your username or password by edit file named docker-compose.yml and ./setup/setup.sh

  1. Compose first with docker-compose build or you can use docker-compose up for build & run.
  2. When compose done, connect to your primary container by using this docker-compose exec mongo-rs0-1 mongo -u "root" -p "root".
  3. And when mongo shell popup, you need to check is it primary or secondary by db.isMaster().
    • (a). You got some returned value, check the object value called by "ismaster" : true or "primary" : "mongo-rs0-1:27017".
    • (b). When it's in primary cluster, continue to step 4. When it's not, continue to 3b.
    • (c). To make your current cluster become primary, execute command below (one by one)
      • cfg = rs.conf();
      • cfg.members[0].priority = 2;
      • rs.reconfig(cfg);
    • (d). Now check the cluster state again, is it primary or not?
  4. Create or Add user to your admin database by using this db.createUser({user: "admin",pwd: "admin",roles: [ { role: "userAdminAnyDatabase", db: "admin" }, { "role" : "clusterAdmin", "db" : "admin" } ]});
  5. Now you're done :D

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.