Skip to content

Commit 470776b

Browse files
martkaczmarekludomikula
authored andcommitted
Add healthchecks to docker-compose-multi.yaml
Added healthchecks and conditions for dependant containers to start only when container's healthy state is confirmed
1 parent 936d3b6 commit 470776b

File tree

1 file changed

+50
-6
lines changed

1 file changed

+50
-6
lines changed

deploy/docker/docker-compose-multi.yaml

+50-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: "3"
21
services:
32

43
##
@@ -14,11 +13,30 @@ services:
1413
volumes:
1514
- ./lowcoder-stacks/data/mongodb:/data/db
1615
restart: unless-stopped
16+
healthcheck: # https://github.com/rodrigobdz/docker-compose-healthchecks?tab=readme-ov-file#mongo
17+
test:
18+
[
19+
"CMD",
20+
"mongosh",
21+
"--quiet",
22+
"127.0.0.1/test",
23+
"--eval",
24+
"'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'",
25+
]
26+
interval: 5s
27+
timeout: 10s
28+
retries: 10
29+
start_period: 40s
1730

1831
redis:
1932
image: redis:7-alpine
2033
container_name: redis
2134
restart: unless-stopped
35+
healthcheck: # https://stackoverflow.com/a/71504657
36+
test: ["CMD-SHELL", "redis-cli ping | grep PONG"]
37+
interval: 1s
38+
timeout: 3s
39+
retries: 10
2240

2341

2442
##
@@ -82,11 +100,20 @@ services:
82100
LOWCODER_SUPERUSER_PASSWORD:
83101
restart: unless-stopped
84102
depends_on:
85-
- mongodb
86-
- redis
103+
mongodb:
104+
condition: service_healthy
105+
restart: true
106+
redis:
107+
condition: service_healthy
108+
restart: true
87109
volumes:
88110
- ./lowcoder-stacks:/lowcoder-stacks
89111
- ./lowcoder-stacks/assets:/lowcoder/assets
112+
healthcheck: #https://stackoverflow.com/questions/71101967/how-should-i-use-grep-in-docker-compose-healthcheck
113+
test: curl -sS http://lowcoder-api-service:8080 | grep -c "Lowcoder API is up and runnig" > /dev/null
114+
interval: 3s
115+
timeout: 5s
116+
retries: 10
90117

91118

92119
lowcoder-node-service:
@@ -101,7 +128,14 @@ services:
101128
LOWCODER_API_SERVICE_URL: "http://lowcoder-api-service:8080"
102129
restart: unless-stopped
103130
depends_on:
104-
- lowcoder-api-service
131+
lowcoder-api-service:
132+
condition: service_healthy
133+
restart: true
134+
healthcheck: #https://stackoverflow.com/questions/71101967/how-should-i-use-grep-in-docker-compose-healthcheck
135+
test: curl -sS http://lowcoder-node-service:6060 | grep -c "Lowcoder Node Service is up and running" > /dev/null
136+
interval: 3s
137+
timeout: 5s
138+
retries: 10
105139

106140
##
107141
## Start Lowcoder web frontend
@@ -120,8 +154,18 @@ services:
120154
LOWCODER_NODE_SERVICE_URL: "http://lowcoder-node-service:6060"
121155
restart: unless-stopped
122156
depends_on:
123-
- lowcoder-node-service
124-
- lowcoder-api-service
157+
lowcoder-node-service:
158+
condition: service_healthy
159+
restart: true
160+
lowcoder-api-service:
161+
condition: service_healthy
162+
restart: true
125163
volumes:
126164
- ./lowcoder-stacks/assets:/lowcoder/assets
165+
healthcheck:
166+
test: curl --fail http://lowcoder-frontend:3000 || exit 1
167+
interval: 5s
168+
retries: 10
169+
start_period: 10s
170+
timeout: 10s
127171

0 commit comments

Comments
 (0)