You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3.4应用升级后健康检查失效,如何修复?

解决Spring Boot 3.4 + Paketo 健康检查失效问题

问题根源

Spring Boot 3.4默认使用无shell的tiny builder构建镜像,而你之前通过--health-cmd指定的健康检查命令依赖shell解析执行,导致容器启动时找不到/bin/sh,触发健康检查失败。

修改方案(优先推荐):调整健康检查为exec模式

通过Spring Boot Maven插件配置,让Paketo的health-checker buildpack生成无需shell的exec类型健康检查命令,具体修改pom.xml中的spring-boot-maven-plugin:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <image>
            <buildpacks>
                <buildpack>paketo-buildpacks/health-checker</buildpack>
            </buildpacks>
            <env>
                <!-- 指定健康检查类型为exec,直接执行命令(无需shell) -->
                <BP_HEALTH_CHECK_TYPE>exec</BP_HEALTH_CHECK_TYPE>
                <!-- 设置健康检查的可执行文件路径 -->
                <BP_HEALTH_CHECK_CMD>/workspace/health-check</BP_HEALTH_CHECK_CMD>
                <!-- 保留健康检查端口配置 -->
                <THC_PORT>8081</THC_PORT>
            </env>
        </image>
    </configuration>
</plugin>

配套操作

移除容器启动时手动指定的--health-cmd /workspace/health-check参数,避免与buildpack生成的健康检查命令冲突。

备选方案:切换回带shell的full builder

如果你的/workspace/health-check脚本必须依赖shell才能运行,可以修改Maven配置,指定使用包含shell的full builder:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <image>
            <!-- 使用包含shell的full builder镜像 -->
            <builder>paketobuildpacks/builder-jammy-full:latest</builder>
            <buildpacks>
                <buildpack>paketo-buildpacks/health-checker</buildpack>
            </buildpacks>
            <env>
                <THC_PORT>8081</THC_PORT>
            </env>
        </image>
    </configuration>
</plugin>

此方案会导致镜像体积增大,仅在脚本无法脱离shell时使用。

内容的提问来源于stack exchange,提问作者dur

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 11:01:06