Solution:
Root Cause: Windows CRLF Line Endings or Missing Binary in Entrypoint Script
When entrypoint shell scripts are edited on Windows host machines, CRLF (
\r\n) line endings are injected into the file. When executed inside a Linux container, the shebang line fails (e.g., looking for
/bin/sh\r), resulting in Exit Code 127 or
no such file or directory.
Step-by-Step Fix:
1Convert CRLF Line Endings to LF (Unix Format):
Convert the entrypoint script on your host machine: dos2unix entrypoint.sh or use VS Code status bar to change
CRLF ->
LF.
2Verify Shell Shebang and Execution Permissions:
Ensure the top line of entrypoint.sh is exactly #!/bin/sh or #!/bin/bash without extra characters.Ensure executable permissions: chmod +x entrypoint.sh.3Validate Command Path in Dockerfile:
Verify ENTRYPOINT or CMD uses valid JSON array syntax: ENTRYPOINT ["/bin/sh", "/app/entrypoint.sh"] instead of string syntax if path resolution fails.
4Rebuild Image Without Cache:
Run: docker build --no-cache -t my-image:latest ..