What does `HEALTHCHECK` do in a Dockerfile?
IntermediateConceptDockerfile Instructions & Builds
Answer
It defines a command Docker runs periodically inside the container; exit 0 = healthy, 1 = unhealthy. State shows in docker ps (healthy/unhealthy/starting). Options: --interval, --timeout, --start-period, --retries. Docker does not restart on unhealthy by itself (Swarm does); Compose depends_on: condition: service_healthy uses it.
HEALTHCHECK --interval=30s --timeout=3s CMD curl -fsS http://localhost:8080/health || exit 1