Skip to content

Commit 761b0ef

Browse files
committed
chore(docker): add service_healthy to start multiple service in order
Signed-off-by: ZheNing Hu <adlternative@gmail.com>
1 parent 0c76447 commit 761b0ef

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

docker-compose.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '3.8'
1+
version: '3.9'
22
services:
33
db:
44
image: mysql:8.0
@@ -14,6 +14,11 @@ services:
1414
- MYSQL_DATABASE=${MYSQL_DATABASE}
1515
- MYSQL_USER=${MYSQL_USER}
1616
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
17+
healthcheck:
18+
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
19+
interval: 3s
20+
timeout: 3s
21+
retries: 10
1722

1823
tinygithub:
1924
build:
@@ -24,23 +29,29 @@ services:
2429
- "8083:8083"
2530
restart: always
2631
depends_on:
27-
- db
32+
db:
33+
condition: service_healthy
2834
environment:
2935
- DB_IP=db
3036
- DB_USER=${MYSQL_USER}
3137
- DB_PASSWORD=${MYSQL_PASSWORD}
3238
- STORAGE=${STORAGE}
3339
- SERVER_IP=${SERVER_IP}
3440
- LOG_LEVEL=debug
35-
41+
healthcheck:
42+
test: [ "CMD", "curl", "localhost:8083" ]
43+
interval: 5s
44+
timeout: 3s
45+
retries: 5
3646
nginx:
3747
image: nginx:latest
3848
container_name: tinygithub-nginx
3949
ports:
4050
- "80:80"
4151
restart: always
4252
depends_on:
43-
- tinygithub
53+
tinygithub:
54+
condition: service_healthy
4455
volumes:
4556
- ./nginx.conf:/etc/nginx/nginx.conf:ro
4657
- ./build/tinygithub-frontend/dist:/usr/share/nginx/html

0 commit comments

Comments
 (0)