We earn commissions when you shop through the links below, at no extra cost to you. Our guides and technical recommendations are written independently of these relationships: a commission never decides what we recommend, how we diagnose a problem or what we publish, and the content does not depend on it. Affiliate disclosure

Docker · Intermediate · 15 min

Fix 'exec ... no such file or directory' in Docker

Fix "exec /entrypoint.sh: no such file or directory": find CRLF line endings, a missing #! interpreter or a glibc binary on Alpine.

Three different causes print exactly the same line and exit code. This runbook reads the first line of the entrypoint inside the image to tell them apart, fixes each at the source, and covers the related permission denied and executable file not found errors. Commands were run on Ubuntu 26.04 with Docker Engine 29.1.3 and alpine:3.20.

See it run

A short replay of real output from commands in this guide, captured on a WSL2 Ubuntu test machine (Docker 29.1.3). The typing is replayed, and the host name, account and MAC addresses are redacted. Your output will differ, and a test machine is not a production server.

Text version of this demo
ops@web-01:~$ docker run --rm ob-entry; echo "exit=$?"
exec /entrypoint.sh: no such file or directory
exit=255

ops@web-01:~$ docker run --rm --entrypoint sh ob-entry -c 'head -n 1 /entrypoint.sh | od -c | head -n 2'
0000000   #   !   /   b   i   n   /   s   h  \r  \n
0000013

ops@web-01:~$ file entrypoint.sh
entrypoint.sh: POSIX shell script, ASCII text executable, with CRLF line terminators

ops@web-01:~$ sed -i 's/\r$//' entrypoint.sh && docker build -q -t ob-entry . >/dev/null 2>&1 && docker run --rm ob-entry
app: starting

The container stops at once with exec /entrypoint.sh: no such file or directory, and yet the file is in the image. The message is misleading: "no such file" usually refers to a different file, the program the kernel needs in order to run yours. Three causes produce exactly the same text, and this runbook tells them apart in a minute: Windows line endings in a script, an interpreter in the first line (#!) that the image does not have, or a binary built against a C library the image does not have. Two related errors, permission denied and executable file not found in $PATH, are covered at the end.

Commands and output were captured on an Ubuntu 26.04 test machine with Docker Engine 29.1.3 and the alpine:3.20 image.

0. Rules of engagement

  1. Do not rebuild blindly. Read the first line of the file inside the image first; it usually names the cause.
  2. Fix the source, not only the image. A line-ending or permission fix applied only inside the Dockerfile comes back the next time someone edits the file.
  3. Keep the failed container until you have read its state if you started it without --rm: docker inspect and docker logs work only while it exists.

1. Match the message

MessageExit code of docker runCauseGo to
exec /entrypoint.sh: no such file or directory255Windows line endings, a missing #! interpreter, or a missing C library loaderSection 2
exec: "/entrypoint.sh": permission denied126The file has no execute permissionSection 4
exec: "nosuch": executable file not found in $PATH127The command is not in the image, or not on PATHSection 5
# Real output from the test machine: an entrypoint script with Windows line endings
exec /entrypoint.sh: no such file or directory

The same line, with the same exit code 255, came from a script whose first line is #!/bin/bash in an Alpine image, and from a binary built on Ubuntu copied into Alpine. Only the next checks separate them.

2. Read the first line inside the image

Override the entrypoint with the image's own shell, so the broken one does not run:

# Show the first line byte by byte: a \r before \n means Windows line endings
docker run --rm --entrypoint sh IMAGE -c 'head -n 1 /entrypoint.sh | od -c | head -n 2'
# Real output from the test machine
0000000   #   !   /   b   i   n   /   s   h  \r  \n
0000013
  • \r before \n: the kernel looks for an interpreter called /bin/sh followed by a carriage return, which does not exist. Go to section 3.1.
  • No \r, and the line names an interpreter: check that it exists in the image (section 3.2).
  • The file is a binary, not a script (od shows 177 E L F): go to section 3.3.
# Does the interpreter named in the first line exist in the image?
docker run --rm --entrypoint sh IMAGE -c 'head -n 1 /entrypoint.sh; ls -l /bin/bash /bin/sh'
# Real output from the test machine (alpine:3.20 has no bash)
#!/bin/bash
ls: /bin/bash: No such file or directory
lrwxrwxrwx    1 root     root            12 Apr 15  2026 /bin/sh -> /bin/busybox

If the image has no shell at all (distroless or scratch images), copy the file out instead: docker create --name tmp IMAGE, docker cp tmp:/entrypoint.sh ., docker rm tmp, and inspect it on the host.

3. Fix

3.1 Windows line endings

On the host, the file shows it plainly:

# On the host: both commands show the carriage return
file entrypoint.sh
head -n 1 entrypoint.sh | cat -A
# Real output from the test machine
entrypoint.sh: POSIX shell script, ASCII text executable, with CRLF line terminators
#!/bin/sh^M$

Convert the file and stop it from coming back:

# Remove the carriage returns (dos2unix entrypoint.sh does the same)
sed -i 's/\r$//' entrypoint.sh
# .gitattributes in the repository root: keep shell scripts with LF on every platform
*.sh text eol=lf

After adding .gitattributes, run git add --renormalize . and commit, so files already in the repository are fixed too. Git on Windows with core.autocrlf=true is the most common source of this problem. A carriage return in a value instead of a script, for example a password in an env file, is a different problem: see Fix a stray carriage return in .env file values.

3.2 The interpreter is not in the image

Either use an interpreter the image has, or install the one the script needs:

  • Change the first line to #!/bin/sh if the script uses only POSIX shell features.
  • Or install it: RUN apk add --no-cache bash on Alpine, RUN apt-get update && apt-get install -y --no-install-recommends bash on Debian-based images.

3.3 A binary built for another C library

# Real output from the test machine: an Ubuntu binary copied into alpine:3.20
exec /app: no such file or directory
# On the host: which loader the binary asks for
file app
# Real output from the test machine (shortened)
app: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2

A binary linked against glibc needs /lib64/ld-linux-x86-64.so.2; Alpine uses musl and does not have it. Build the binary in the same base image you run it in (a multi-stage build with alpine in both stages), use a glibc-based runtime image such as a Debian slim image, or build a static binary. A binary built for another CPU architecture fails differently, with exec format error.

4. permission denied

# Real output from the test machine
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: exec: "/entrypoint.sh": permission denied
# The mode of the file inside the image
docker run --rm --entrypoint sh IMAGE -c 'ls -l /entrypoint.sh'
# Real output from the test machine: no x bits
-rw-r--r--    1 root     root            31 Oct 30 22:22 /entrypoint.sh
  • Set the mode in the repository, so it travels with the file: git update-index --chmod=+x entrypoint.sh, then commit.
  • Or set it in the image: COPY --chmod=755 entrypoint.sh /entrypoint.sh. This needs BuildKit; the legacy builder stops with the --chmod option requires BuildKit. Without BuildKit, use RUN chmod 755 /entrypoint.sh after the COPY.

5. executable file not found in $PATH

# Real output from the test machine: docker run with a command the image does not have
docker: Error response from daemon: ... exec: "nosuch": executable file not found in $PATH
# Real output from the test machine: docker exec into an Alpine container
OCI runtime exec failed: exec failed: unable to start container process: exec: "bash": executable file not found in $PATH

The command does not exist in the image, or it is not in a directory on PATH. For docker exec, use the shell the image has (docker exec -it CONTAINER sh on Alpine and BusyBox images). For an entrypoint or command, give the full path, or check what the image really contains with docker run --rm --entrypoint sh IMAGE -c 'echo $PATH; ls /usr/local/bin'.

6. Verify

# The image's entrypoint and command as Docker stores them
docker image inspect --format 'entrypoint={{json .Config.Entrypoint}} cmd={{json .Config.Cmd}}' IMAGE
# Real output from the test machine
entrypoint=["/entrypoint.sh"] cmd=null

Rebuild, run the container, and check that it reaches its first log line and stays up: docker run -d --name test IMAGE, docker logs test, docker ps --filter name=test.

7. Rollback and prevention

  • Rollback: run the previous image tag or digest while you fix the source; the change is in the build, not in running data.
  • .gitattributes with *.sh text eol=lf in every repository that builds images.
  • Keep the execute bit in Git, and check it in CI: git ls-files -s '*.sh' shows mode 100755 for executable files.
  • Build and run on the same base image, or ship static binaries.
  • A CI smoke test that starts the image and waits for the first log line catches all of these before a deploy.

References

Official reference

docs.docker.com ↗

Technical steps are original explanations; consult the upstream documentation for version-specific details.

Behavior differs by distribution and tool version. Commands are examples for authorized systems; review output for secrets before sharing.

Found this useful?

Follow us on YouTube for video explainers, and find us on Facebook to keep up with what is new.