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

Docker启动Python应用报错:entrypoint.sh不存在(文件实际存在)

问题排查与解决方案

核心原因分析

你遇到的docker exec /home/app/entrypoint.sh: no such file or directory错误,并非脚本文件不存在,而是以下两种常见情况导致:

1. Alpine镜像缺少bash解释器

python:alpine3.18基于Alpine Linux,默认仅预装ash shell,没有bash。你的entrypoint.sh开头指定了#!/bin/bash,系统找不到该解释器,因此抛出错误。

解决方案二选一:

  • 方案A:修改脚本shebang
    将entrypoint.sh第一行改为#!/bin/sh(ash完全兼容你的脚本中的所有命令):
    #!/bin/sh
    # 其余脚本内容不变
    
  • 方案B:在Dockerfile中安装bash
    在RUN chmod +x entrypoint.sh前添加安装命令:
    RUN apk add --no-cache bash
    

2. 脚本换行符为Windows格式(CRLF)

如果你的entrypoint.sh是在Windows环境下编写的,换行符会是CRLF(\r\n),而Linux容器仅识别LF(\n)。此时脚本的shebang行会被解析为#!/bin/bash\r,系统会尝试寻找不存在的/bin/bash\r路径,触发错误。

解决方案:

  • 手动转换换行符:用VS Code等编辑器,右下角切换换行符为LF后保存脚本。
  • Dockerfile中自动转换:在RUN chmod +x entrypoint.sh前添加转换命令:
    RUN sed -i 's/\r$//' entrypoint.sh
    

额外优化建议

  1. 简化Dockerfile路径:由于已经切换到WORKDIR /home/app,CMD可以写成相对路径,更简洁:
    CMD ["./entrypoint.sh"]
    
  2. 合并Dockerfile命令,减少镜像层数:
    RUN apk add --no-cache bash \
        && sed -i 's/\r$//' entrypoint.sh \
        && chmod +x entrypoint.sh
    

内容的提问来源于stack exchange,提问作者Paulo Ricardo Mesquita

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 17:45:14