Skip to content

Commit aab4309

Browse files
committed
Docker compose refining
1 parent 0b2046e commit aab4309

File tree

1 file changed

+40
-26
lines changed

1 file changed

+40
-26
lines changed

docker-compose.yaml

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,48 @@
11
version: '3'
22
services:
3-
primary:
4-
image: mongo
5-
container_name: mongodb-primary
3+
mongo1:
4+
image: mongo:5
5+
command: ["mongod", "--replSet", "myReplicaSet", "--bind_ip", "localhost,mongo1"]
66
ports:
7-
- "27017:27017"
8-
environment:
9-
MONGO_INITDB_REPLICA_SET: ReplicaSet
7+
- 27017:27017
8+
networks:
9+
- mongoCluster
1010

11-
secondary1:
12-
image: mongo
13-
container_name: mongodb-secondary1
11+
mongo2:
12+
image: mongo:5
13+
command: ["mongod", "--replSet", "myReplicaSet", "--bind_ip", "localhost,mongo2"]
1414
ports:
15-
- "27018:27017"
16-
environment:
17-
MONGO_INITDB_REPLICA_SET: ReplicaSet
15+
- 27018:27017
16+
networks:
17+
- mongoCluster
1818

19-
secondary2:
20-
image: mongo
21-
container_name: mongodb-secondary2
19+
mongo3:
20+
image: mongo:5
21+
command: ["mongod", "--replSet", "myReplicaSet", "--bind_ip", "localhost,mongo3"]
2222
ports:
23-
- "27019:27017"
24-
environment:
25-
MONGO_INITDB_REPLICA_SET: ReplicaSet
23+
- 27019:27017
24+
networks:
25+
- mongoCluster
2626

27-
arbiter:
28-
image: mongo
29-
container_name: mongodb-arbiter
30-
ports:
31-
- "27020:27017"
32-
environment:
33-
MONGO_INITDB_REPLICA_SET: ReplicaSet
34-
MONGO_INITDB_ARBITER: "yes"
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

0 commit comments

Comments
 (0)