From a13f971dbcfbb9452bccde01d595ef914b409c4b Mon Sep 17 00:00:00 2001 From: z3r0Luck Date: Fri, 12 Jun 2020 23:51:46 +0300 Subject: [PATCH] Chat Ro0m --- mongoDB_swarm/docker-compose.yml | 36 ++++++++++++++++++++++++++++++++ mongoDB_swarm/mongors/Dockerfile | 5 +++++ mongoDB_swarm/mongors/init.sh | 15 +++++++++++++ mongo_swarm/docker-mongo-swarm | 1 - 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 mongoDB_swarm/docker-compose.yml create mode 100644 mongoDB_swarm/mongors/Dockerfile create mode 100644 mongoDB_swarm/mongors/init.sh delete mode 160000 mongo_swarm/docker-mongo-swarm diff --git a/mongoDB_swarm/docker-compose.yml b/mongoDB_swarm/docker-compose.yml new file mode 100644 index 0000000..8e9efd3 --- /dev/null +++ b/mongoDB_swarm/docker-compose.yml @@ -0,0 +1,36 @@ +version: '3.3' +services: + rs1: + image: mongo:3.4 + command: mongod --replSet "rs0" + networks: + - mongo + rs2: + image: mongo:3.4 + command: mongod --replSet "rs0" + networks: + - mongo + + rs3: + image: mongo:3.4 + command: mongod --replSet "rs0" + networks: + - mongo + + rs: + image: ericsmalling/mongors:3.4 + build: + context: ./mongors + + networks: + - mongo + deploy: + restart_policy: + condition: on-failure + delay: 5s + max_attempts: 10 + +networks: + mongo: + driver: overlay + attachable: true diff --git a/mongoDB_swarm/mongors/Dockerfile b/mongoDB_swarm/mongors/Dockerfile new file mode 100644 index 0000000..6dd64da --- /dev/null +++ b/mongoDB_swarm/mongors/Dockerfile @@ -0,0 +1,5 @@ +FROM mongo:3.2 +COPY init.sh /tmp/init.sh +RUN chmod +x /tmp/init.sh +LABEL maintainer="Eric Smalling " +CMD /tmp/init.sh diff --git a/mongoDB_swarm/mongors/init.sh b/mongoDB_swarm/mongors/init.sh new file mode 100644 index 0000000..4d21890 --- /dev/null +++ b/mongoDB_swarm/mongors/init.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# Make sure 3 replicas available +for rs in rs1 rs2 rs3;do + mongo --host $rs --eval 'db' + if [ $? -ne 0 ]; then + exit 1 + fi +done + +# Connect to rs1 and configure replica set if not done +status=$(mongo --host rs1 --quiet --eval 'rs.status().members.length') +if [ $? -ne 0 ]; then + # Replicaset not yet configured + mongo --host rs1 --eval 'rs.initiate({ _id: "rs0", version: 1, members: [ { _id: 0, host : "rs1" }, { _id: 1, host : "rs2" }, { _id: 2, host : "rs3" } ] })'; +fi diff --git a/mongo_swarm/docker-mongo-swarm b/mongo_swarm/docker-mongo-swarm deleted file mode 160000 index 5e7d455..0000000 --- a/mongo_swarm/docker-mongo-swarm +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5e7d455c5c84d6886b3dc589dd00eb62c160d9fc