# exec /entrypoint.sh: exec 格式错误：/usr/bin/env: 'bash\r': 没有那个文件或目录

- **ID:** `docker/entrypoint-script-dos-line-endings`
- **领域:** docker
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

入口点脚本具有 Windows 风格的 CRLF 换行符（\r\n）而不是 Unix 风格的 LF（\n），导致 shebang 解释器尝试执行 'bash\r'（包含回车符）时失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Docker 20.10.22 | active | — | — |
| Docker 24.0.4 | active | — | — |
| Docker 25.0.0 | active | — | — |

## 解决方案

1. ```
   在主机上使用 'dos2unix' 将入口点脚本转换为 Unix 换行符：'dos2unix entrypoint.sh'，或在构建镜像前使用 'sed -i 's/\r$//' entrypoint.sh'。
   ```
2. ```
   在 Dockerfile 中，在 COPY 之后添加 RUN 命令修复换行符：'RUN sed -i 's/\r$//' /entrypoint.sh'。
   ```
3. ```
   配置 Git 在检出时自动转换换行符：在主机上设置 'git config core.autocrlf input'，然后重新克隆或检出仓库。
   ```

## 无效尝试

- **** — The issue is not the shell type but the carriage return character in the shebang line; changing the shebang does not remove the \r character. (90% 失败率)
- **** — The base image does not affect the line endings of the script; the problem is in the script file itself, which is copied from the host. (95% 失败率)
- **** — The container fails to start due to the entrypoint error, so 'docker exec' cannot be used because the container is not running. (100% 失败率)
