Docker Compose
Docker Compose health check
Add this healthcheck to a service in your Compose file. Replace the port and endpoint with the
ones used by your application. The example uses Node.js 18 or newer for the built-in fetch API.
services:
app:
build: .
ports:
- '3000:3000'
healthcheck:
test:
- CMD
- node
- -e
- "fetch('http://127.0.0.1:3000/health').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))"
interval: 30s
timeout: 5s
retries: 3
start_period: 10s