Command not found in container
Production Risk
Container cannot start; service is unavailable until image is corrected.
Exit code 127 means the shell could not find the specified command. In Kubernetes, this typically means the container image does not contain the binary specified in the command or args field of the pod spec, or the PATH is not set correctly. It is a very common error when switching to minimal/distroless images.
- 1Binary referenced in command/args does not exist in the container image
- 2Wrong image tag deployed — command existed in a previous version
- 3Distroless or minimal image missing standard tools (bash, sh, curl, etc.)
- 4PATH environment variable not set correctly in the container
Container exits immediately with code 127; logs show "command not found" or "no such file".
kubectl logs mypod --previous # /bin/sh: myapp: not found kubectl describe pod mypod # Last State: Terminated Reason: Error Exit Code: 127
expected output
/bin/sh: myapp: not found
Fix 1
Verify binary exists in the image
WHEN Unsure whether the binary is present in the image
# Run a debug container with the same image kubectl run debug --image=myimage:tag --restart=Never -it --rm -- /bin/sh -c "which myapp && ls -la /usr/local/bin/"
Why this works
Confirms whether the binary is present and on the PATH inside the image.
Fix 2
Use the full path in command spec
WHEN Binary exists but PATH is not set
# In pod spec
spec:
containers:
- name: myapp
image: myimage:tag
command: ["/usr/local/bin/myapp"]Why this works
Absolute paths bypass PATH lookup entirely.
Kubernetes Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev