z3r0Luck
5 years ago
4 changed files with 56 additions and 1 deletions
@ -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 |
@ -0,0 +1,5 @@ |
|||||
|
FROM mongo:3.2 |
||||
|
COPY init.sh /tmp/init.sh |
||||
|
RUN chmod +x /tmp/init.sh |
||||
|
LABEL maintainer="Eric Smalling <smalls@docker.com>" |
||||
|
CMD /tmp/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 |
@ -1 +0,0 @@ |
|||||
Subproject commit 5e7d455c5c84d6886b3dc589dd00eb62c160d9fc |
|
Loading…
Reference in new issue