Skip to content

Commit 1abb21f

Browse files
committed
improve health checks for container composition
1 parent d802918 commit 1abb21f

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

docker-compose.yaml

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ services:
1818
tmpfs:
1919
- /linuxfr.org/public/tmp:size=100M
2020
healthcheck:
21-
test: curl --fail http://localhost:3000
21+
test: ["CMD", "curl", "--silent", "--fail", "--head", "http://localhost:3000"]
22+
interval: 10s
23+
start_period: 5s
2224
depends_on:
2325
database:
2426
condition: service_healthy
@@ -33,7 +35,9 @@ services:
3335
env_file:
3436
- deployment/default.env
3537
healthcheck:
36-
test: curl --fail -I http://localhost:9000
38+
test: ["CMD", "curl", "--silent", "--fail", "--head", "http://localhost:9000"]
39+
interval: 10s
40+
start_period: 5s
3741
depends_on:
3842
redis:
3943
condition: service_healthy
@@ -45,7 +49,9 @@ services:
4549
env_file:
4650
- deployment/default.env
4751
healthcheck:
48-
test: curl --fail http://localhost:8000/status
52+
test: ["CMD", "curl", "--silent", "--fail", "--head", "http://localhost:8000/status"]
53+
interval: 10s
54+
start_period: 5s
4955
depends_on:
5056
redis:
5157
condition: service_healthy
@@ -66,8 +72,16 @@ services:
6672
published: 127.0.0.1:80
6773
protocol: tcp
6874
healthcheck:
69-
test: curl --fail http://$$DOMAIN && curl --fail http://$$DOMAIN/img && curl --fail -I http://$$DOMAIN/b
75+
test: ["CMD", "curl", "--silent", "--fail", "--fail-early", "--head", "http://$$DOMAIN", "http://$$DOMAIN/img", "http://$$DOMAIN/b", "http://$$IMAGE_DOMAIN/status"]
76+
interval: 10s
77+
start_period: 5s
7078
depends_on:
79+
database:
80+
condition: service_healthy
81+
restart: true
82+
redis:
83+
condition: service_healthy
84+
restart: true
7185
linuxfr.org:
7286
condition: service_healthy
7387
restart: true
@@ -77,6 +91,11 @@ services:
7791
linuxfr-img:
7892
condition: service_healthy
7993
restart: true
94+
networks:
95+
default:
96+
aliases:
97+
- ${DOMAIN}
98+
- ${IMAGE_DOMAIN}
8099

81100
database:
82101
build:
@@ -88,14 +107,18 @@ services:
88107
published: 127.0.0.1:3306
89108
protocol: tcp
90109
healthcheck:
91-
test: mysql -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD --execute "SHOW DATABASES;"
110+
test: ["CMD", "mysql", "-h", "127.0.0.1", "-u", "$$MYSQL_USER", "--password=$$MYSQL_PASSWORD", "--execute", "\"SHOW DATABASES;\""]
111+
interval: 10s
112+
start_period: 5s
92113
volumes:
93114
- data-database:/var/lib/mysql
94115

95116
redis:
96117
image: docker.io/redis:5
97118
healthcheck:
98-
test: redis-cli --raw incr ping
119+
test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
120+
interval: 10s
121+
start_period: 5s
99122
volumes:
100123
- data-redis:/data
101124

0 commit comments

Comments
 (0)