This error occurs when Docker cannot execute an entrypoint script or binary, typically because of Windows-style line endings (CRLF) in shell scripts. Converting files to Unix line endings (LF) resolves the issue in most cases.
When you see `standard_init_linux.go: exec user process caused: no such file or directory`, Docker is trying to execute your entrypoint script or binary but failing to find the interpreter or required libraries. Despite the confusing message, the file usually exists - the issue is that Docker cannot properly parse or execute it. The most common cause is Windows-style line endings (CRLF) in shell scripts. When a script like `entrypoint.sh` contains `#!/bin/bash\r\n` instead of `#!/bin/bash\n`, Linux interprets this as looking for an interpreter named `/bin/bash\r` (with a carriage return), which does not exist. This typically happens when developers create or edit scripts on Windows, or when Git automatically converts line endings. Less commonly, this error can indicate missing dynamic libraries in minimal base images like Alpine, or architecture mismatches between the build and runtime environments.
First, verify whether line endings are the culprit. You can inspect your script file using:
file entrypoint.shIf it shows "CRLF line terminators" or "with CRLF", that's the problem. You can also check with:
cat -A entrypoint.sh | head -5If you see ^M at the end of lines, those are carriage return characters from Windows.
The easiest fix is to convert the file to Unix line endings:
dos2unix entrypoint.shIf dos2unix is not installed, you can install it:
# Ubuntu/Debian
sudo apt-get install dos2unix
# macOS
brew install dos2unix
# Alpine
apk add dos2unixIf you cannot install dos2unix, use sed to strip carriage returns:
sed -i 's/\r$//' entrypoint.shOn macOS, you may need:
sed -i '' 's/\r$//' entrypoint.shYou can also fix this directly in your editor:
VS Code: Look at the bottom-right status bar. Click on "CRLF" and select "LF", then save the file.
Notepad++: Go to Edit > EOL Conversion > Unix (LF), then save.
JetBrains IDEs: File > Line Separators > LF - Unix and macOS
If you cannot control the source files (e.g., they come from a Windows-only environment), fix them during the Docker build:
# For Debian/Ubuntu based images
RUN apt-get update && apt-get install -y dos2unix \
&& dos2unix /app/entrypoint.sh \
&& apt-get remove -y dos2unix && apt-get autoremove -y
# For Alpine based images
RUN apk add --no-cache dos2unix \
&& dos2unix /app/entrypoint.sh \
&& apk del dos2unixAlternatively, use sed without installing additional packages:
RUN sed -i 's/\r$//' /app/entrypoint.shPrevent this issue from recurring by configuring Git. Create or update .gitattributes in your repository root:
# Force LF line endings for shell scripts
*.sh text eol=lf
# Force LF for other common script types
*.bash text eol=lf
*.zsh text eol=lf
Dockerfile text eol=lf
docker-entrypoint* text eol=lfAlternatively, configure Git globally:
git config --global core.autocrlf inputThis converts CRLF to LF on commit but does not modify files on checkout.
After fixing the line endings, you must rebuild the image for changes to take effect:
docker build --no-cache -t your-image:tag .The --no-cache flag ensures Docker does not use cached layers that might contain the old file.
If line endings are not the issue, the problem might be missing dynamic libraries. This is common with Go binaries on Alpine:
# Option 1: Build a static binary (Go)
ENV CGO_ENABLED=0
RUN go build -o /app/myapp .
# Option 2: Use a compatible base image
FROM golang:1.21-alpine AS builder
# ... build steps ...
FROM alpine:3.18
RUN apk add --no-cache libc6-compat
COPY --from=builder /app/myapp /app/myappYou can check what libraries a binary needs:
ldd /app/myappWhy the error message is misleading: The Linux kernel reports "no such file or directory" when it cannot find the interpreter specified in a script's shebang line. When #!/bin/bash\r has a carriage return, the kernel looks for a program literally named /bin/bash\r, which does not exist, hence the error.
Multi-stage builds: When using multi-stage Docker builds, line ending issues in scripts copied between stages can be tricky. Consider converting line endings in the first stage before copying to the final image.
Binary compatibility: If you are building on Ubuntu/Debian and deploying to Alpine, remember that Alpine uses musl libc while most other distributions use glibc. Use CGO_ENABLED=0 for Go, or ensure your runtime image has compatible libraries.
ARM vs x86: This error can also occur when trying to run an image built for a different architecture. Use docker buildx for multi-architecture builds:
docker buildx build --platform linux/amd64,linux/arm64 -t myimage:latest .image operating system "linux" cannot be used on this platform
How to fix 'image operating system linux cannot be used on this platform' in Docker
manifest unknown: manifest unknown
How to fix 'manifest unknown' in Docker
cannot open '/etc/passwd': Permission denied
How to fix 'cannot open: Permission denied' in Docker
Error response from daemon: failed to create the ipvlan port
How to fix 'failed to create the ipvlan port' in Docker
toomanyrequests: Rate exceeded for anonymous users
How to fix 'Rate exceeded for anonymous users' in Docker Hub