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

Docker容器启动报错:entrypoint文件不存在排查求助

Docker容器启动报entrypoint文件不存在错误

问题现象

项目Docker镜像在主Windows机器及其他开发者机器均可正常运行,但在第二台Windows机器启动项目时,PHP容器报错:

$ docker-compose logs -f php
Attaching to project-name-php-1
project-name-php-1 | exec /usr/local/bin/docker-entrypoint: no such file or directory

已完成排查

  • 确认Dockerfile中ENTRYPOINT语法无误:ENTRYPOINT ["docker-entrypoint"]
  • 验证镜像内存在目标文件且权限正常:
    docker run -it --rm --entrypoint bash theimage/inuse:thetag
    root@209618ad969c:/var/www# ls -l /usr/local/bin
    -rwxr-xr-x 1 root root      924 Jul 22 12:04 docker-entrypoint
    
  • 确认文件并非通过卷挂载到容器,权限配置无异常

问题根源

第二台Windows机器上的docker-entrypoint.sh文件使用了Windows CRLF换行符,而Linux容器仅识别LF换行符。容器执行脚本时,shebang行#!/bin/bash会被解析为#!/bin/bash\r,系统无法找到该路径,因此报"文件不存在"错误。

解决方案

1. 修正文件换行符

  • 使用编辑器(如VS Code)打开本地的docker-entrypoint.sh文件,右下角查看换行符标识,若为CRLF,点击切换为LF后保存。
  • 配置Git自动转换换行符(避免后续修改时再次出现问题):
    git config --global core.autocrlf input
    
    该配置会在提交代码时将CRLF转为LF,拉取代码时保持LF格式。

2. 重新构建镜像并重启容器

# 重新构建PHP服务镜像
docker-compose build php

# 清理旧容器并启动服务
docker-compose down
docker-compose up -d

验证方法

进入容器查看文件换行符,若行尾有^M则说明是换行符问题:

docker run -it --rm --entrypoint bash theimage/inuse:thetag
cat -A /usr/local/bin/docker-entrypoint

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 20:24:52