Crlf docker entrypoint
Agent Skills for d9 (Directus 9 fork) — install with: npx skills add LaWebcapsule/d9-skills
npx -y skills add LaWebcapsule/d9-skills --skill crlf-docker-entrypointAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Prevent shell script failures in Docker containers caused by Windows CRLF line endings.
The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
4.6 KB, as published. Nobody here has run it
CRLF Line Endings Break Shell Scripts in Docker Containers
Purpose
Prevent /bin/sh execution failures caused by Windows CRLF (\r\n) line endings in shell scripts that are copied into Linux-based Docker containers (Alpine, Debian, etc.). The \r character is interpreted as part of the command or flag, producing cryptic errors like illegal option - on set -e.
Triggers
- Creating or editing any
.shfile on a Windows machine that will beCOPY'd orADD'd into a Docker image. - Modifying a
Dockerfilethat copies shell scripts from a Windows host into a Linux container. - Debugging a Docker build or container startup that fails with
illegal option,not found, or\rrelated errors from/bin/sh.
Behavior
- Detect: Check if the
.shfile has CRLF endings. Runfile <script>.sh(shows "CRLF" if present) orod -c <script>.sh | head(look for\r\n). - Fix at source (preferred): Configure
.gitattributesin the repository root to force LF on shell scripts:
Then re-checkout the file:*.sh text eol=lfgit checkout -- <script>.sh. - Fix in Dockerfile (fallback): Add a
RUNinstruction immediately after theCOPY:COPY entrypoint.sh /app/entrypoint.sh RUN sed -i 's/\r$//' /app/entrypoint.sh - Fix locally before build: Run
sed -i 's/\r$//' <script>.shon the host beforedocker build.
Always prefer the .gitattributes approach because it prevents the problem at the root for all contributors.
Errors Prevented
/bin/sh: illegal option -when the container runsset -efrom an entrypoint script.exec format errorornot foundon scripts with a shebang line containing a trailing\r.- Silent failures in multi-line shell commands where
\rcorrupts variable values or command arguments.
Restrictions
Hard Boundaries
- Never disable
set -eas a workaround for the CRLF issue; the real fix is correcting line endings. - Never convert binary files with
sed; only target.shand other text-based scripts.
Soft Boundaries
- Prefer
.gitattributesover Dockerfilesedto keep the fix version-controlled and automatic. - Avoid relying on editor-level settings alone (e.g., VS Code
files.eol), as they do not protect against other tools or contributors.
Self-Check
- The
.shfile reportsASCII text(notASCII text, with CRLF line terminators) when inspected withfile. - The Docker container starts without
/bin/sherrors related to line endings. - A
.gitattributesentry exists for*.shwithtext eol=lf. - After cloning on a fresh Windows machine, the
.shfiles still have LF endings.
Examples
Example 1: Entrypoint fails on Alpine container
Scenario: A docker-entrypoint.sh is created on Windows with VS Code (default CRLF). The Dockerfile copies it in and sets it as ENTRYPOINT. On docker run, the container exits immediately with:
/bin/sh: illegal option -
Diagnosis: docker run --rm --entrypoint cat myimage /app/docker-entrypoint.sh | od -c | head reveals \r\n sequences.
Fix applied:
- Added to
.gitattributes:*.sh text eol=lf - Re-normalized the file:
git add --renormalize docker-entrypoint.sh git commit -m "fix: force LF endings on shell scripts" - Rebuilt the image. Container starts cleanly.
Example 2 (Edge Case): Script works locally but fails in CI
Scenario: A developer runs docker build on macOS (which uses LF natively) and everything works. CI runs on a Windows runner with Git configured as core.autocrlf=true. The checkout converts .sh files to CRLF. The Docker build succeeds (no syntax check at build time), but the container crashes at runtime.
Diagnosis: The CI log shows the container exiting with code 2. Adding RUN cat -A /app/entrypoint.sh to the Dockerfile reveals lines ending with ^M$ instead of just $.
Fix applied:
- Added
.gitattributeswith*.sh text eol=lf(this overridescore.autocrlffor matching files). - Added a defensive
RUN sed -i 's/\r$//' /app/entrypoint.shin the Dockerfile as a belt-and-suspenders measure for environments where.gitattributesmight be bypassed. - CI pipeline now passes on both Windows and Linux runners.