Skip to content

Via a single command run a MongoDB Sharded Cluster on a set of Docker containers on your workstation

License

Notifications You must be signed in to change notification settings

pkdone/sharded-mongodb-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MongoDB Sharded Cluster Deployment Running In Docker Containers

Provides the ability to execute a single command to build and run a MongoDB Sharded Cluster on a local workstation 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 consisting of 11 separate containers for:

  • 6 mongod processes for the 2 shard replica sets
  • 3 mongod processes for the configdb replica set
  • 2 mongos router processes

All the containers are visible to each other on the same internal network. Once running, the MongoDB cluster is accessible directly from your workstation via the 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 takes a few minutes to download all the base Docker images. The containers will normally come up in less than 5 seconds when the command is executed the second and subsequent times.

Prerequisites

  • Your workstation is running a recent version of Linux, Windows or Mac OS X
  • Docker is already installed on your workstation
  • Docker Compose is already installed on your workstation
  • The MongoDB Shell is already installed on your workstation for to you to issue commands to the running database cluster from your workstation (alternatively use the MongoDB Compass graphical tool to connect to the cluster)

Build, Run & Connect

  1. Launch a command line terminal in the base of folder of this project and execute the following command to build and start all the containers in the Docker Compose project:
docker-compose up --build -d
  1. Connect to the running MongoDB cluster from the MongoDB Shell (the shell will attempt to connect to the first of the two mongos endpoints) and then issue the command to print the states of the sharded cluster:
mongosh --port 27017
sh.status()

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

Tips

  • To show all the running docker containers for this Docker Compose project, run:
docker-compose ps
  • To show the container logs for one of the mongos routers, run:
docker-compose logs mongos-router0
  • To execute a terminal session directly in one of the mongos containers, to then invoke the MongoDB Shell directly accessing the local mongos process, run:
docker-compose exec mongos-router0 /bin/bash
mongosh
  • To execute a terminal session directly in one of the mongod containers and then view the mongod process logs, run:
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:
docker-compose down

About

Via a single command run a MongoDB Sharded Cluster on a set of Docker containers on your workstation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published