如何对运行在Docker Container中的Spring Boot应用程序进行健康检查?

人气:783 发布:2022-10-16 标签: docker spring-boot dockerfile docker-compose health-check

问题描述

我在Docker容器中运行一个Spring Boot应用程序,使用Docker文件在容器中启动该应用程序。如何检查容器内的Spring Boot应用程序的运行状况?

如果容器停止或应用程序未运行,则需要根据健康检查自动重启容器或应用程序。这样,我可以确保Spring Boot应用程序始终处于启动和运行状态。

推荐答案

如果要将Spring Bootactuator/health用作扩展坞健康检查,您必须将其添加到扩展坞撰写文件中:

    healthcheck:
      test: "curl --fail --silent localhost:8081/actuator/health | grep UP || exit 1"
      interval: 20s
      timeout: 5s
      retries: 5
      start_period: 40s

编辑: 这里的端口是management.server.port。如果未指定,则应为server.port value(默认为8080)

1,008