Skip to content

Commit 83db6a9

Browse files
committed
initiate replica set configuration in Docker Compose
1 parent 1ff6f7a commit 83db6a9

2 files changed

Lines changed: 5 additions & 14 deletions

File tree

docker-compose.yaml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,26 @@ services:
77
ports:
88
- "6379:6379"
99
mongo1:
10-
image: mongo:7.0
10+
image: mongo:5
1111
container_name: mongo1
1212
command: [ "--replSet", "my-replica-set", "--bind_ip_all", "--port", "30001" ]
1313
ports:
1414
- 30001:30001
1515
healthcheck:
16-
test: echo "try { rs.status() } catch (err) { rs.initiate({_id:'my-replica-set',members:[{_id:0,host:'mongo1:30001',priority:1},{_id:1,host:'mongo2:30002',priority:0.5},{_id:2,host:'mongo3:30003',priority:0.5}]}) }" | mongosh --port 30001 --quiet
16+
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
1717
interval: 10s
18-
volumes:
19-
- "mongo1_data:/data/db"
20-
- "mongo1_config:/data/configdb"
2118
mongo2:
22-
image: mongo:7.0
19+
image: mongo:5
2320
container_name: mongo2
2421
command: [ "--replSet", "my-replica-set", "--bind_ip_all", "--port", "30002" ]
2522
ports:
2623
- 30002:30002
27-
volumes:
28-
- "mongo2_data:/data/db"
29-
- "mongo2_config:/data/configdb"
3024
mongo3:
31-
image: mongo:7.0
25+
image: mongo:5
3226
container_name: mongo3
3327
command: [ "--replSet", "my-replica-set", "--bind_ip_all", "--port", "30003" ]
3428
ports:
3529
- 30003:30003
36-
volumes:
37-
- "mongo3_data:/data/db"
38-
- "mongo3_config:/data/configdb"
3930
mongo-express:
4031
image: mongo-express
4132
container_name: mongo-express

src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ management.metrics.tags.application=${spring.application.name}
99
#
1010
# mongodb
1111
#
12-
mongodb.uri=mongodb://127.0.0.1:30001
12+
mongodb.uri=mongodb://mongo1:30001,mongo2:30002,mongo3:30003/?replicaSet=my-replica-set
1313
#
1414
# kafka
1515
#

0 commit comments

Comments
 (0)