Skip to content

Commit

Permalink
fixed replica sets on docker-compose
Browse files Browse the repository at this point in the history
Co-authored-by: Gaurav Padam <[email protected]>
  • Loading branch information
TejasNair9977 and Gauravpadam committed Nov 5, 2023
1 parent aab4309 commit 2461a04
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 37 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,7 @@ dist
.pnp.*

# ingore genrated APIdocs
apidoc
apidoc

# data generated by mongo replicas
data/
57 changes: 21 additions & 36 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,48 +1,33 @@
version: '3'
version: "3.8"

services:
mongo1:
image: mongo:5
command: ["mongod", "--replSet", "myReplicaSet", "--bind_ip", "localhost,mongo1"]
container_name: mongo1
command: ["--replSet", "my-replica-set", "--bind_ip_all", "--port", "30001"]
volumes:
- ./data/mongo-1:/data/db
ports:
- 27017:27017
networks:
- mongoCluster
- 30001:30001
healthcheck:
test: test $$(echo "rs.initiate({_id:'my-replica-set',members:[{_id:0,host:\"mongo1:30001\"},{_id:1,host:\"mongo2:30002\"},{_id:2,host:\"mongo3:30003\"}]}).ok || rs.status().ok" | mongo --port 30001 --quiet) -eq 1
interval: 10s
start_period: 30s

mongo2:
image: mongo:5
command: ["mongod", "--replSet", "myReplicaSet", "--bind_ip", "localhost,mongo2"]
container_name: mongo2
command: ["--replSet", "my-replica-set", "--bind_ip_all", "--port", "30002"]
volumes:
- ./data/mongo-2:/data/db
ports:
- 27018:27017
networks:
- mongoCluster
- 30002:30002

mongo3:
image: mongo:5
command: ["mongod", "--replSet", "myReplicaSet", "--bind_ip", "localhost,mongo3"]
container_name: mongo3
command: ["--replSet", "my-replica-set", "--bind_ip_all", "--port", "30003"]
volumes:
- ./data/mongo-3:/data/db
ports:
- 27019:27017
networks:
- mongoCluster

init-replica:
image: mongo:5
depends_on:
- mongo1
- mongo2
- mongo3
command:
- mongosh
- --eval
- >
rs.initiate({
_id: 'myReplicaSet',
members: [
{_id: 0, host: 'mongo1'},
{_id: 1, host: 'mongo2'},
{_id: 2, host: 'mongo3'}
]
})
networks:
mongoCluster:
driver: bridge
- 30003:30003

0 comments on commit 2461a04

Please sign in to comment.