Skip to content
exec: 'command': executable file not found in $PATH

exec: 'command': executable file not found in $PATH

DodaTech 2 min read

The error “exec: ‘command’: executable file not found in $PATH” occurs during a RUN instruction in a Dockerfile when the specified command is not available inside the container image.

What It Means

Docker builds each layer by running a command in a temporary container based on the previous layer. When a RUN instruction references a command that is not installed in the container, the shell or exec form returns this error and the build fails immediately.

Why It Happens

  • The base image is minimal (e.g., alpine, scratch, distroless) and does not include common tools.
  • The command name is misspelled or the wrong package provides it.
  • The RUN instruction appears before the package install command.
  • The command was installed in a previous RUN but the image was cached and the cache was invalidated.
  • The exec form (RUN ["command", "arg"]) is used but the command is not in PATH.

How to Fix It

1. Use the exec form with the full path

RUN ["/usr/bin/curl", "-sL", "https://example.com"]

2. Install the missing package

RUN apt-get update && apt-get install -y curl

3. For Alpine, use apk

RUN apk add --no-cache curl

4. Check what is in the base image

RUN which command_name  # debug: see if it exists

5. Combine RUN instructions to avoid ordering issues

RUN apt-get update && apt-get install -y \
    curl \
    git \
    && rm -rf /var/lib/apt/lists/*

FAQ

What is the difference between shell form and exec form in RUN?
Shell form (RUN command arg) runs via /bin/sh -c. Exec form (RUN ["command", "arg"]) runs the command directly without a shell. Exec form does not expand environment variables and requires the full path.
Why does 'apt-get install' work in one RUN but not another?
Each RUN instruction creates a new layer. If you install a package in layer 1 and then run a command in layer 2, the command is available. But if layer 1’s installation failed or was cached incorrectly, the command won’t exist in layer 2.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro