Skip to content

Commit 2461a04

Browse files
fixed replica sets on docker-compose
Co-authored-by: Gaurav Padam <[email protected]>
1 parent aab4309 commit 2461a04

File tree

2 files changed

+25
-37
lines changed

2 files changed

+25
-37
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,7 @@ dist
130130
.pnp.*
131131

132132
# ingore genrated APIdocs
133-
apidoc
133+
apidoc
134+
135+
# data generated by mongo replicas
136+
data/

docker-compose.yaml

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,33 @@
1-
version: '3'
1+
version: "3.8"
2+
23
services:
34
mongo1:
45
image: mongo:5
5-
command: ["mongod", "--replSet", "myReplicaSet", "--bind_ip", "localhost,mongo1"]
6+
container_name: mongo1
7+
command: ["--replSet", "my-replica-set", "--bind_ip_all", "--port", "30001"]
8+
volumes:
9+
- ./data/mongo-1:/data/db
610
ports:
7-
- 27017:27017
8-
networks:
9-
- mongoCluster
11+
- 30001:30001
12+
healthcheck:
13+
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
14+
interval: 10s
15+
start_period: 30s
1016

1117
mongo2:
1218
image: mongo:5
13-
command: ["mongod", "--replSet", "myReplicaSet", "--bind_ip", "localhost,mongo2"]
19+
container_name: mongo2
20+
command: ["--replSet", "my-replica-set", "--bind_ip_all", "--port", "30002"]
21+
volumes:
22+
- ./data/mongo-2:/data/db
1423
ports:
15-
- 27018:27017
16-
networks:
17-
- mongoCluster
24+
- 30002:30002
1825

1926
mongo3:
2027
image: mongo:5
21-
command: ["mongod", "--replSet", "myReplicaSet", "--bind_ip", "localhost,mongo3"]
28+
container_name: mongo3
29+
command: ["--replSet", "my-replica-set", "--bind_ip_all", "--port", "30003"]
30+
volumes:
31+
- ./data/mongo-3:/data/db
2232
ports:
23-
- 27019:27017
24-
networks:
25-
- mongoCluster
26-
27-
init-replica:
28-
image: mongo:5
29-
depends_on:
30-
- mongo1
31-
- mongo2
32-
- mongo3
33-
command:
34-
- mongosh
35-
- --eval
36-
- >
37-
rs.initiate({
38-
_id: 'myReplicaSet',
39-
members: [
40-
{_id: 0, host: 'mongo1'},
41-
{_id: 1, host: 'mongo2'},
42-
{_id: 2, host: 'mongo3'}
43-
]
44-
})
45-
46-
networks:
47-
mongoCluster:
48-
driver: bridge
33+
- 30003:30003

0 commit comments

Comments
 (0)