A Docker container exits with 'no such file or directory' though the file exists
standard_init_linux.go:190: exec user process caused "no such file or directory"Short answer
The kernel returns this error when the file's interpreter is missing, not only the file. That is a script whose #! line names a shell the image lacks or ends in a carriage return, or a Go binary linked against glibc running on Alpine. Check the first line or the build flags, then fix that.
Fix it fast
1Find out which cause you have
Run the image with a shell and confirm the file really is there.
docker run --rm -it --entrypoint sh my-image -c 'ls -l /app'2Match what you see, then jump to its fix
- 1
The binary is listed by ls but will not start; the image is Alpine or another musl base.A Go binary built with cgo runs on AlpineFix - 2
The failing file is a .sh script starting with #!/bin/bash on a small image.The entrypoint script starts with a shell the image does not haveFix - 3
The script was edited or checked out on Windows; the first line looks correct.The script has Windows line endingsFix
- 1
What does the error look like?
standard_init_linux.go:190: exec user process caused "no such file or directory"
Cause 1 of 3
A Go binary built with cgo runs on Alpine
1Check
Alpine is built around musl libc. On native builds cgo is enabled by default, so the binary may expect a different C library. The execve man page says ENOENT also covers a missing ELF interpreter.
go env CGO_ENABLED2Fix
Build with cgo off, as Docker's Go guide does, or build in a golang alpine stage.
RUN CGO_ENABLED=0 GOOS=linux go build -o /app/server .3Verify
Rebuild and run the container.
docker build -t my-image . && docker run --rm my-imageConfirmed by pkg.go.dev
Cause 2 of 3
The entrypoint script starts with a shell the image does not have
1Check
The first line must name an executable interpreter that exists in the image; otherwise execve returns ENOENT.
head -n 1 entrypoint.sh
docker run --rm --entrypoint sh my-image -c 'ls -l /bin/bash /bin/sh'2Fix
Use an interpreter the image has (for example #!/bin/sh) or install the shell in the image.
#!/bin/sh3Verify
Rebuild and start the container.
docker run --rm my-imageConfirmed by man7.org
Cause 3 of 3
The script has Windows line endings
1Check
Git writes CRLF on Windows checkouts when eol is crlf or autocrlf is set, so the #! line ends with an extra carriage return.
head -n 1 entrypoint.sh | od -c | tail -n 32Fix
Force LF for shell scripts in .gitattributes, then check the files out again.
# .gitattributes
*.sh text eol=lf3Verify
od no longer shows \r before the newline.
head -n 1 entrypoint.sh | od -cConfirmed by git-scm.com
How do I stop it coming back?
- Build Go services with CGO_ENABLED=0 unless you need cgo, and then match the base image to the build image.
- Keep an .gitattributes rule for *.sh.
- Run the final image in CI, not only the build stage.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
dnf fails to download repo metadata in a CentOS 8 Docker build
The same Dockerfile built fine before 2022
CentOS Linux 8 reached end of life on 31 December 2021 and its content left the mirrors.
2 causes, each with a fixServers
pip install confluent-kafka fails because librdkafka/rdkafka.h is missing
pip stops while building confluent-kafka from source
The error means pip is compiling confluent-kafka from source, and the compiler cannot find the librdkafka C headers.
3 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fixServers
A dev container port does not open in the browser when Docker runs on a remote host
If your application only accepts calls from localhost, it will reject connections from published ports
Three things usually break it: the app listens only on localhost inside the container, so published ports are rejected; you open the container port instead of the mapped localhost port VS Code shows; or you changed appPort or a Compose ports list and did not rebuild.
3 causes, each with a fix