-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-compose.yaml
68 lines (67 loc) · 1.85 KB
/
docker-compose.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
services:
# 啟動3個mongo container用以建置Replica Set
KiwiRS-mongo1:
hostname: KiwiRS-mongo1
image: mongo:${MONGO_IMAGE_VERSION}
expose:
- 27017
ports:
- ${MONGO1_HOST_PORT}:27017
restart: always
command: mongod --replSet my-mongo-set
volumes:
- ${MONGO1_DATA_STORAGE}:/data/db
- ${MONGO1_CONFIG_STORAGE}:/data/configdb
KiwiRS-mongo2:
hostname: KiwiRS-mongo2
image: mongo:${MONGO_IMAGE_VERSION}
expose:
- 27017
ports:
- ${MONGO2_HOST_PORT}:27017
restart: always
command: mongod --replSet my-mongo-set
volumes:
- ${MONGO2_DATA_STORAGE}:/data/db
- ${MONGO2_CONFIG_STORAGE}:/data/configdb
KiwiRS-mongo3:
hostname: KiwiRS-mongo3
image: mongo:${MONGO_IMAGE_VERSION}
expose:
- 27017
ports:
- ${MONGO3_HOST_PORT}:27017
restart: always
command: mongod --replSet my-mongo-set
volumes:
- ${MONGO3_DATA_STORAGE}:/data/db
- ${MONGO3_CONFIG_STORAGE}:/data/configdb
# 初始化Mongo Replica Server
mongoinit:
image: mongo:${MONGO_IMAGE_VERSION}
# 這個Container只會執行一次
# 此Container可能會依據mongo1~3的啟動狀態受到一定程度的影響
# 啟動後記得查看此Container的Log,看到{ "ok" : 1 }才算成功!
restart: "on-failure"
depends_on:
- KiwiRS-mongo1
- KiwiRS-mongo2
- KiwiRS-mongo3
command: >
mongo --host KiwiRS-mongo1:27017 --eval 'config = { "_id" : "my-mongo-set", "members" : [
{
"_id" : 0,
"host" : "KiwiRS-mongo1:27017",
"priority" : 1
},
{
"_id" : 1,
"host" : "KiwiRS-mongo2:27017",
"priority" : 0.5
},
{
"_id" : 2,
"host" : "KiwiRS-mongo3:27017",
"priority" : 0.5
}
] }; rs.initiate(config);'