docker config_error ai_generated true

错误:容器健康检查命令未找到:/healthcheck.sh:没有那个文件或目录

Error: Container health check command not found: /healthcheck.sh: No such file or directory

ID: docker/healthcheck-command-not-found

其他格式: JSON · Markdown 中文 · English
92%修复率
87%置信度
1证据数
2025-01-12首次发现

版本兼容性

版本状态引入弃用备注
Docker 20.10.21 active
Docker 24.0.6 active
Docker 25.0.2 active

根因分析

Dockerfile 中的 HEALTHCHECK 指令引用了容器镜像中指定路径下不存在的脚本或二进制文件。

English

The HEALTHCHECK instruction in the Dockerfile references a script or binary that does not exist inside the container image at the specified path.

generic

官方文档

https://docs.docker.com/engine/reference/builder/#healthcheck

解决方案

  1. 确保健康检查脚本在 HEALTHCHECK 行之前通过 COPY 指令复制到镜像中。示例:COPY healthcheck.sh /healthcheck.sh && HEALTHCHECK --interval=30s --timeout=3s CMD /healthcheck.sh
  2. 使用内置命令如 'curl' 或 'wget' 进行健康检查,并在 Dockerfile 中安装它们。示例:RUN apt-get update && apt-get install -y curl && HEALTHCHECK CMD curl -f http://localhost/ || exit 1
  3. 如果使用不带脚本的 shell 命令,使用 'CMD-SHELL' 形式:HEALTHCHECK --interval=30s CMD-SHELL pgrep nginx || exit 1

无效尝试

常见但无效的做法:

  1. 70% 失败

    The HEALTHCHECK command runs inside the container, so the script must be present in the image filesystem; the build context alone is insufficient.

  2. 85% 失败

    HEALTHCHECK does not support relative paths; it always interprets the command as an absolute path or a shell command. './healthcheck.sh' will be treated as a literal filename starting with '.'.

  3. 60% 失败

    Many minimal base images (e.g., alpine, distroless) do not include curl, causing a 'not found' error for the healthcheck command.