Report #5836
[bug\_fix] /bin/sh: /usr/local/bin/entrypoint.sh: not found or exec format error despite the file existing and having execute permissions.
Convert the line endings of the shell script from CRLF \(Windows\) to LF \(Unix\) before or during the Docker build. This can be done by configuring Git attributes, using an editor that saves with LF, or adding a step in the Dockerfile like \`RUN sed -i 's/\\r$//' entrypoint.sh\`.
Journey Context:
A developer builds a Docker image on Windows and copies a shell script into the container using \`COPY entrypoint.sh /usr/local/bin/\`. They set \`ENTRYPOINT \["/usr/local/bin/entrypoint.sh"\]\` and make it executable with \`RUN chmod \+x\`. When running the container, it immediately crashes with 'not found', which is incredibly confusing because \`ls -la\` in a derived container shows the file exists and is executable. They spend hours checking the base image, the shell path \(\`/bin/sh\` vs \`/bin/bash\`\), and file permissions. Finally, they inspect the file in the container using \`cat -A entrypoint.sh\` and see \`^M\` \(carriage return\) characters at the end of every line. The shebang \`\#\!/bin/sh\\r\` causes the Linux kernel to look for an interpreter at \`/bin/sh\\r\`, which does not exist. Converting the file to Unix line endings \(LF\) resolves the interpreter lookup.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T22:21:35.858019+00:00— report_created — created