Maaz Zindani

Loading the index…

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

docker run fails because the executable is not found in the container

Errordocker: Error response from daemon: failed to create task for container: ... exec: "<name>": executable file not found in $PATH

Short answer

Docker looked for the program you named inside the container image and did not find it. Either the image does not contain that program, or you gave a shell line such as cd app && node x.js to something that runs without a shell. Check what the image has with --entrypoint sh, then fix the command.

  • Applies to Docker Engine 28
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open a shell in the image, bypassing its entrypoint, and look for the program yourself.

    docker run --rm -it --entrypoint sh <image>
    # inside:
    command -v <program>
  2. 2Match what you see, then jump to its fix

    1. 1command -v prints nothing for the programThe program is not installed in the imageFix
    2. 2The name in the error contains spaces or && , such as "cd app && node server.js"A whole command line was passed as one program nameFix
    3. 3The program named in the error is something you typed after the image name, such as bashAn argument after the image name replaced the command, or the entrypointFix

What does the error look like?

  • docker: Error response from daemon: failed to create task for container: ... exec: "<name>": executable file not found in $PATH
  • OCI runtime create failed: ... executable file not found in $PATH: unknown

Cause 1 of 3

The program is not installed in the image

1Check

A slim or minimal image may not include what runs fine on your machine. The program also may exist under a path outside PATH.

echo $PATH
ls /usr/local/bin /usr/bin | head

2Fix

Install it in the Dockerfile, use a base image that includes it, or call it by its full path.

RUN apt-get update && apt-get install -y --no-install-recommends <package> && rm -rf /var/lib/apt/lists/*

3Verify

Run the program in a new container.

docker run --rm <image> <program> --version

Confirmed by docs.docker.com

Did this fix it?

Cause 2 of 3

A whole command line was passed as one program name

1Check

Exec form does not start a shell. A JSON array with one string is read as one executable name, not a command line.

grep -n "CMD\|ENTRYPOINT" Dockerfile

2Fix

Split the words into array items, or call a shell on purpose with sh -c. Prefer WORKDIR over cd.

WORKDIR /app
CMD ["node", "server.js"]

3Verify

The container starts and stays up.

docker build -t myapp .
docker run --rm myapp

Confirmed by docs.docker.com

Did this fix it?

Cause 3 of 3

An argument after the image name replaced the command, or the entrypoint

1Check

Arguments after the image are appended to an exec-form ENTRYPOINT, or replace CMD. The --entrypoint flag overrides the image's entrypoint and clears its default CMD.

docker image inspect --format '{{json .Config.Entrypoint}} {{json .Config.Cmd}}' <image>

2Fix

Run your command through the entrypoint override when you want a different program.

docker run --rm -it --entrypoint bash <image>

3Verify

The shell opens, or the program prints its output.

docker run --rm --entrypoint sh <image> -c 'echo ok'

Confirmed by docs.docker.com

Did this fix it?

How do I stop it coming back?

  • Use exec form with one word per array item, and WORKDIR instead of cd.
  • Test a new image with --entrypoint sh before wiring it into compose.
  • Use a multi-stage build and copy the final binary with its full path into the runtime 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

Next step

Want this handled for good?

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