Last active
November 29, 2016 13:43
-
-
Save katopz/96f72c86c944c0bc7734e69c2ad4d76b to your computer and use it in GitHub Desktop.
For setup 3 MongoDB replica set in Docker container and use data volume for db. will need https://gist.github.com/katopz/0f553b431302d9313ebfa7d48b53db89
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Setup Docker | |
NETWORK_NAME=${1:-my-mongo-cluster} | |
REPLICASET_NAME=${2:-my-mongo-set} | |
# Disconnect old container if has. | |
docker network disconnect -f $NETWORK_NAME mongo0 | |
docker network disconnect -f $NETWORK_NAME mongo1 | |
docker network disconnect -f $NETWORK_NAME mongo2 | |
# Remove old network if has. | |
docker network rm $NETWORK_NAME | |
# Remove dangling. | |
docker volume rm $(docker volume ls -qf dangling=true) | |
# Create docker network name. | |
docker network create $NETWORK_NAME | |
# List docker network. | |
docker network ls | |
## Setup Mongo | |
# List existing mongo process. | |
pgrep mongo | |
# Kill existing process if has. | |
pkill mongo | |
# Create mongo container 0. | |
. setup-container.sh 0 $NETWORK_NAME $REPLICASET_NAME | |
# Create mongo container 1. | |
. setup-container.sh 1 $NETWORK_NAME $REPLICASET_NAME | |
# Create mongo container 2. | |
. setup-container.sh 2 $NETWORK_NAME $REPLICASET_NAME | |
# Provide hint. | |
echo 'Hint for minimum architecture of a replica set has three members.' | |
echo '-----------------------------------------------------------------' | |
echo '> rs.initiate({"_id":"my-mongo-set","members":[{"_id":0,"host":"mongo0:27017","priority":1},{"_id":1,"host":"mongo1:27017","priority":0.5},{"_id":2,"host":"mongo2:27017","priority":0.3}]})' | |
echo '-----------------------------------------------------------------' | |
# List existing mongo process. | |
pgrep mongo | |
# Connect to available host. | |
docker exec -it mongo0 mongo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment