Keywords: Docker | Line Endings | CRLF to LF | standard_init_linux.go | Container Startup Error
Abstract: This article provides an in-depth analysis of the standard_init_linux.go:190: exec user process caused "no such file or directory" error in Docker containers. Through practical case studies, it demonstrates the incompatibility between CRLF line endings in Windows and LF in Linux environments, detailing EOL conversion methods using Notepad++ and VSCode. The article also covers key knowledge points including shell interpreter selection and ENTRYPOINT format configuration, offering comprehensive troubleshooting workflows and multiple solutions to help developers completely resolve such container startup issues.
Error Phenomenon and Background Analysis
When running Docker images on Windows 10 environment, users encounter the standard_init_linux.go:190: exec user process caused "no such file or directory" error. This error typically occurs during container startup when Docker attempts to execute the executable file specified by ENTRYPOINT or CMD, but the system cannot locate the corresponding file or properly parse the file format.
Core Issue: Line Ending Incompatibility
According to the best answer analysis, the primary issue lies in the line ending differences between Windows and Linux systems. Windows uses CRLF (Carriage Return + Line Feed, i.e., \r\n) as line endings, while Linux systems use LF (Line Feed, i.e., \n). When shell scripts are edited in Windows environment without proper format conversion, the Linux environment within Docker containers cannot correctly recognize the script files.
Here is a typical error scenario: users create run.sh script on Windows system, where the script content is correct but the container fails to start due to CRLF line endings.
Solution: EOL Conversion
Using Notepad++ for Conversion
In Notepad++, conversion can be completed through the following steps:
- Open the target script file
- Click the "Edit" menu
- Select "EOL Conversion"
- Choose "Convert to LF (Unix)"
After conversion, save the file and rebuild the Docker image to resolve the issue.
Using VSCode for Conversion
For VSCode users, the conversion process is more straightforward:
- Open the target script file
- Check the status bar at the bottom right corner
- Click the button showing "CRLF"
- Select "LF" from the pop-up options
This method quickly completes format conversion, ensuring scripts execute correctly in Linux environment.
Additional Solutions
Shell Interpreter Compatibility
Referring to other answers, shell interpreter selection is also an important factor. Some base images (such as Alpine Linux) do not include bash by default, only providing /bin/sh. If a script specifies #!/bin/bash but bash doesn't exist in the image, the same "no such file or directory" error will occur.
Solutions include:
- Changing shebang to
#!/bin/sh - Installing bash in Dockerfile:
apk add --no-cache bash(for Alpine) - Ensuring correct shebang path, avoiding non-existent paths like
#!/usr/local/bin/bash
ENTRYPOINT Format Configuration
ENTRYPOINT format configuration is also crucial. Docker supports two forms of ENTRYPOINT:
- Exec form:
ENTRYPOINT ["executable", "param1", "param2"] - Shell form:
ENTRYPOINT command param1 param2
The exec form is recommended as it ensures proper process signal handling and resource cleanup. In some cases, changing ENTRYPOINT ["/run.sh"] to ENTRYPOINT ["sh", "/run.sh"] can resolve the issue, because the former relies on script executable permissions and correct shebang, while the latter explicitly specifies the shell interpreter.
In-depth Technical Analysis
The standard_init_linux.go:190 error originates from Docker's container initialization process. When Docker starts a container, it calls relevant functions in standard_init_linux.go to set up the container environment and execute user-specified processes. The error message indicates that the execve system call failed, with specific reasons including:
- File not found: Incorrect executable file path or file genuinely doesn't exist
- File format error: File is not a valid executable format or contains unparsable content
- Permission issues: File lacks execute permissions
- Interpreter problems: Script-specified interpreter doesn't exist or has incorrect path
In Windows environment, CRLF line endings cause script files to be recognized as binary files containing invalid characters in Linux environment, thus triggering the "no such file or directory" error.
Best Practice Recommendations
To avoid such issues, the following best practices are recommended:
- Unified Development Environment: Standardize using LF as line ending standard in team development
- Editor Configuration: Set default line ending to LF in code editors
- Version Control Configuration: Configure
core.autocrlfasinputorfalsein Git - Container Validation: Verify script executability by entering container via
docker run -it <image> /bin/shbefore building image - Use Multi-stage Builds: Ensure final stage uses correct file format in multi-stage builds
Troubleshooting Workflow
When encountering standard_init_linux.go:190 error, follow this troubleshooting workflow:
- Check file existence: Use
ls -lain container to confirm target file exists - Verify file permissions: Ensure script file has execute permissions (
chmod +x) - Check line endings: Use
cat -Aorfilecommand to check file format - Validate shebang: Confirm interpreter specified in script first line exists and has correct path
- Test script execution: Manually execute script in container to verify functionality
- Check ENTRYPOINT format: Ensure correct ENTRYPOINT format is used
Through systematic troubleshooting, such container startup issues can be quickly identified and resolved.