Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

A Docker container exits with 'no such file or directory' though the file exists

Errorstandard_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.

  • Applies to Docker 27, Go 1.23, Alpine 3.20
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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'
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2The 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. 3The script was edited or checked out on Windows; the first line looks correct.The script has Windows line endingsFix

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_ENABLED

2Fix

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-image

Confirmed by pkg.go.dev

Did this fix it?

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/sh

3Verify

Rebuild and start the container.

docker run --rm my-image

Confirmed by man7.org

Did this fix it?

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 3

2Fix

Force LF for shell scripts in .gitattributes, then check the files out again.

# .gitattributes
*.sh text eol=lf

3Verify

od no longer shows \r before the newline.

head -n 1 entrypoint.sh | od -c

Confirmed by git-scm.com

Did this fix it?

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

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.