Healthcheck

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

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

#!/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

volumes:
  - ./healthcheck.sh:/healthcheck.sh
healthcheck:
  test: ["CMD", "/healthcheck.sh"]
  interval: 10s
  timeout: 5s
  retries: 5