一个 health check 告诉 Docker(或编排工具)如何确定容器的应用程序是否 实际在工作,而不仅仅是在运行。容器的进程可能在运行,而应用程序却已损坏(挂起、无法连接到其数据库)— 健康检查可以检测到这一点,以便平台可以做出反应。
定义健康检查
# in a Dockerfile
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
CMD curl -f http://localhost:3000/health || exit 1
# → Docker runs this command periodically; exit 0 = healthy, non-zero = unhealthy
[, , , ]
