Coder Social home page Coder Social logo

saurabharch / sharded-mongodb-docker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andris9/sharded-mongodb-docker

0.0 1.0 0.0 5 KB

Runs a MongoDB Sharded Cluster on a set of Docker containers on your laptop/PC from a single command

License: MIT License

Dockerfile 31.93% Shell 68.07%

sharded-mongodb-docker's Introduction

Example Containerised MongoDB Sharded Cluster Project

A project requiring a single command to build and run a MongoDB Sharded Cluster in a local laptop/PC environment with each MongoDB component (Mongod, Mongos) running in a separate Docker container. Uses a Docker Compose project to launch the sharded MongoDB cluster containerised deployment.

Each element in the deployment topology (9 Mongod processes for the 2 shard replica sets and the configdb replica set + 2 Mongos processes) runs in its own Docker container and all the containers are visible to each other on the same internal network. Once running, the MongoDB cluster is accessible directly from your laptop/PC, via localhost forwarded ports 27107 & 27108 which connect to each of the two Mongos processes respectively.

The first time you execute the command to build and run the containers, it take a couple of minutes to download all the base Docker images. When executed the second and subsequent times, the containers will all come up in around 10 seconds.

Prerequisites

  • Your laptop/PC is running a recent version of Linux, Windows or Mac OS X
  • Docker is already installed on your laptop/PC
  • Docker Compose is already installed on your laptop/PC
  • MongoDB is already installed on your laptop/PC to enable the Mongo Shell to be run directly from your laptop/PC (alternatively use MongoDB Compass to connect to the cluster)

Build, Run & Connect

  1. Launch a command line terminal in the base sharded-mongodb-docker folder and execute the following command to build and start all the containers in the Docker Compose project:
sudo docker-compose up --build -d
  1. Show all the running docker containers for this Docker Compose project:
sudo docker-compose ps
  1. Connect to the MongoDB cluster from the Mongo Shell (the Shell should connect to the first of the two Mongos endpoints):
mongo --port 27017
sh.status()
exit

Note: Use port 27018 instead, above, if you want to connect to the second Mongos.

Tips

  • To show the container logs for one of the Mongos servers, run:
sudo docker-compose logs mongos-router0
  • To execute a terminal session directly in one of the Mongos containers and then execute the Mongo Shell directly accessing the local Mongos process, run:
sudo docker-compose exec mongos-router0 /bin/bash
mongo
  • To execute a terminal session directly in one of the Mongod containers and then view the Mongod process' logs, run:
sudo docker-compose exec shard0-replica0 /bin/bash
cat /data/db/mongod.log
  • To shutdown and remove all the Docker Compose project's running containers (ready for you to rebuild and run again), run:
sudo docker-compose down

sharded-mongodb-docker's People

Contributors

pkdone avatar

Watchers

James Cloos avatar

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.