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

- **ID:** `docker/healthcheck-command-not-found`
- **领域:** docker
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Docker 20.10.21 | active | — | — |
| Docker 24.0.6 | active | — | — |
| Docker 25.0.2 | active | — | — |

## 解决方案

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
   ```

## 无效尝试

- **** — The HEALTHCHECK command runs inside the container, so the script must be present in the image filesystem; the build context alone is insufficient. (70% 失败率)
- **** — 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 '.'. (85% 失败率)
- **** — Many minimal base images (e.g., alpine, distroless) do not include curl, causing a 'not found' error for the healthcheck command. (60% 失败率)
