Skip to content

Healthcheck

Health check in docker-compose.yml is usually done as:

docker-compose.yml
healthcheck:
test: ['CMD', 'curl', '--fail', 'http://localhost:8080/health']
interval: 10s
timeout: 5s
retries: 5

but when curl or wget are not available in minimalistic images the same can be achieved using following healthcheck.sh script

healthcheck.sh
#!/bin/bash
exec 5<> /dev/tcp/localhost/8080
cat <&5 &
printf "GET /health HTTP/1.0\r\n\r\n" >&5

then in docker compose

docker-compose.yml
volumes:
- ./healthcheck.sh:/healthcheck.sh
healthcheck:
test: ['CMD', '/healthcheck.sh']
interval: 10s
timeout: 5s
retries: 5