Skip to content

fix: convert entrypoint.sh line endings at Docker build time#9

Merged
curlysasha merged 1 commit intomasterfrom
claude/issue-7-20260107-1119
Jan 8, 2026
Merged

fix: convert entrypoint.sh line endings at Docker build time#9
curlysasha merged 1 commit intomasterfrom
claude/issue-7-20260107-1119

Conversation

@curlysasha
Copy link
Owner

Summary

This PR fixes issue #7 where the Docker container fails to start on Windows 11 with the error "exec /entrypoint.sh: no such file or directory".

Changes

  • Modified Dockerfile: Added sed command to strip CRLF line endings from entrypoint.sh during build
  • Added .gitattributes file to enforce LF line endings for all shell scripts

Root Cause

When Git on Windows checks out files, it converts LF to CRLF. When Docker copies entrypoint.sh into the Linux container, the shebang becomes #!/bin/sh\r which the kernel can't interpret.

Solution

The sed command strips any CRLF endings during the Docker build process, ensuring correct LF endings inside the container regardless of how the file was checked out.

Testing

Windows users should:

  1. Rebuild the Docker image: docker-compose build --no-cache
  2. Start the container: docker-compose up -d

Closes #7


Generated with Claude Code

- Add sed command in Dockerfile to strip CRLF line endings from entrypoint.sh
- Add .gitattributes to enforce LF line endings for shell scripts
- Fixes issue #7 where Docker container fails to start on Windows 11

This fix works immediately without requiring users to re-clone the repository.
The sed command ensures correct line endings inside the container regardless
of how the file was checked out on the host system.

Co-authored-by: curlysasha <curlysasha@users.noreply.github.com>
@claude
Copy link

claude bot commented Jan 8, 2026

Code Review - PR #9

Summary

This PR addresses a critical cross-platform compatibility issue where Docker containers fail to start on Windows due to CRLF line ending conflicts. The solution is well-targeted and effective.


✅ Strengths

  1. Root Cause Analysis: Correctly identifies that Git on Windows converts LF to CRLF, causing the shebang (#!/bin/sh) to become #!/bin/sh\r, which Linux cannot interpret.

  2. Dual-Layer Solution:

    • Build-time fix (sed in Dockerfile): Ensures immediate resolution regardless of how files are checked out
    • Prevention layer (.gitattributes): Prevents future occurrences for new clones
  3. Non-Breaking: The sed command is idempotent - it safely handles files that already have LF endings.

  4. Clear Documentation: The inline comment explains the purpose concisely.


🔍 Code Quality Assessment

Dockerfile changes (Dockerfile:48-49):

# Convert line endings to LF (fixes Windows CRLF issues) and make executable
RUN sed -i 's/\r$//' /entrypoint.sh && chmod +x /entrypoint.sh
  • ✅ Command chaining with && is correct
  • ✅ Comment is helpful and concise
  • ✅ The sed expression correctly strips CR characters

.gitattributes (.gitattributes:1-5):

# Ensure shell scripts always use LF line endings on all platforms
*.sh text eol=lf

# Ensure other text files maintain consistent line endings
* text=auto
  • ✅ Proper shell script enforcement
  • text=auto is a good default for other files
  • ✅ Well-commented

🐛 Potential Issues

None identified - the implementation is solid for this specific fix.


⚡ Performance Considerations

  • Minimal impact: The sed command runs once during build, adding negligible time
  • No runtime overhead: Line ending conversion happens at build time only

🔒 Security Concerns

None - This change:

  • Does not introduce new attack vectors
  • Does not expose sensitive information
  • Only modifies line endings in a shell script during container build

🧪 Test Coverage

Observations:

  • No automated tests added (which is reasonable for a build configuration fix)
  • PR description includes manual testing instructions for Windows users

Recommendation:
While automated testing of line endings in Docker builds is complex, consider:

  1. Adding a validation step in the Dockerfile to verify the shebang is correct:
    RUN head -1 /entrypoint.sh | grep -q '^#!/bin/sh$' || (echo "Error: Invalid shebang in entrypoint.sh" && exit 1)
    This would catch the issue during build rather than at runtime.

💡 Suggestions (Optional Enhancements)

1. Extend .gitattributes coverage

Consider adding other text file types that might be affected:

*.sh text eol=lf
*.py text eol=lf
*.json text eol=lf
*.yml text eol=lf
*.yaml text eol=lf
*.conf text eol=lf
* text=auto

2. Add build validation

As mentioned above, consider adding a validation step:

# Convert line endings to LF (fixes Windows CRLF issues) and make executable
RUN sed -i 's/\r$//' /entrypoint.sh && \
    chmod +x /entrypoint.sh && \
    head -1 /entrypoint.sh | grep -q '^#!/bin/sh$'

3. Consider applying fix to all shell scripts

If there are other shell scripts in the future:

RUN find / -name "*.sh" -type f -exec sed -i 's/\r$//' {} \; 2>/dev/null || true

However, the current targeted approach is cleaner for now.


📋 Verdict

APPROVED

This is a well-crafted fix that:

  • Solves the reported issue completely
  • Uses best practices for cross-platform compatibility
  • Includes both immediate fix and prevention
  • Has clear documentation
  • Introduces no security or performance concerns

The PR is ready to merge. The optional suggestions above are enhancements, not blockers.


📚 Related Best Practices

For future reference, this fix follows Docker best practices:

Great work on this fix! 🎉

@curlysasha curlysasha merged commit 09d9a26 into master Jan 8, 2026
1 check passed
@curlysasha curlysasha deleted the claude/issue-7-20260107-1119 branch January 8, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Не находит entrypoint.sh

1 participant