Contained command not found
Exit code 127 indicates that the command specified as the container's CMD or ENTRYPOINT could not be found within the container's PATH. This is a common error caused by a missing dependency, a typo in a command, or an incorrect PATH environment variable.
- 1The specified command is not installed in the base image.
- 2There is a typo in the CMD or ENTRYPOINT instruction in the Dockerfile.
- 3The command is located in a directory that is not included in the system's PATH variable.
- 4The script is using Windows-style line endings (CRLF) which confuses Linux shells.
A Dockerfile's ENTRYPOINT refers to 'node' but the base image is 'alpine', which does not include Node.js by default.
# Dockerfile FROM alpine:latest WORKDIR /app COPY . . # 'node' command does not exist in the 'alpine' base image ENTRYPOINT ["node", "app.js"]
expected output
OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "node": executable file not found in $PATH: unknown
Fix 1
Install the Missing Dependency
WHEN The command is a required package that isn't in the base image.
# Dockerfile for Debian/Ubuntu FROM ubuntu RUN apt-get update && apt-get install -y nodejs ... # Dockerfile for Alpine FROM alpine RUN apk add --no-cache nodejs ...
Why this works
This adds a layer to the image that downloads and installs the required program, making it available in the PATH.
Fix 2
Use an Official Base Image
WHEN You are building an image for a standard application like Node.js, Python, etc.
# Use the official Node.js image instead of a generic one FROM node:18-alpine WORKDIR /app COPY . . CMD ["node", "app.js"]
Why this works
Official images come pre-configured with the necessary runtime, dependencies, and PATH settings, which is more reliable and efficient than building it yourself.
Fix 3
Correct the Command or Path
WHEN The command is misspelled or located in a non-standard directory.
# If command is at /opt/my-app/run.sh ENTRYPOINT ["/opt/my-app/run.sh"]
Why this works
Using an absolute path to the executable ensures it can be found regardless of the PATH environment variable's configuration.
✕ Copy binaries from your host machine directly into the image.
This often leads to glibc/musl incompatibilities and missing linked libraries. Always install dependencies using the image's native package manager.
Bash Manual - Exit Status
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev