Exit code 127 means "command not found"—the binary or script specified in your container command does not exist. Verify the path, install missing dependencies, or fix your Dockerfile.
Exit code 127 is a standard Linux error code meaning "command not found." The container attempted to execute a command or binary that doesn't exist in the container filesystem. This isn't a Kubernetes-specific error—it's the container runtime reporting that the specified entrypoint, command, or script cannot be located. The issue is always in the container image or pod specification, not in Kubernetes itself.
View the error message to identify what's not found:
kubectl logs <pod-name>
kubectl logs <pod-name> --previousCommon error patterns:
- "/bin/bash: command not found" - bash not installed
- "exec: ./start.sh: not found" - script doesn't exist or bad shebang
- "python: command not found" - Python not in image
Check what command Kubernetes is trying to run:
kubectl get pod <pod-name> -o jsonpath='{.spec.containers[0].command}'
kubectl get pod <pod-name> -o jsonpath='{.spec.containers[0].args}'Compare with what's in the image:
docker run --rm myimage:latest ls -la /app/
docker run --rm myimage:latest which pythonEnsure paths match exactly.
Reproduce the issue outside Kubernetes:
# Run with the same command
docker run --rm myimage:latest /app/start.sh
# If that fails, try interactively
docker run -it --rm myimage:latest /bin/sh
# Then check if command exists
which python
ls -la /app/If it fails locally, fix the Dockerfile.
Add the missing command to your image:
# For Alpine
RUN apk add --no-cache bash python3 curl
# For Debian/Ubuntu
RUN apt-get update && apt-get install -y python3 curl
# For multi-stage builds, copy the binary
COPY --from=builder /app/mybin /usr/local/bin/mybinRebuild and push:
docker build -t myimage:latest .
docker push myimage:latestAvoid relying on PATH—use full paths:
# Fragile - depends on PATH
command: ["python", "app.py"]
# Robust - explicit path
command: ["/usr/bin/python3", "/app/app.py"]Find the correct path:
docker run --rm myimage:latest which python3Scripts may fail with "not found" due to incorrect shebangs or line endings:
# Check for Windows line endings
file start.sh
# Shows: "start.sh: ASCII text, with CRLF line terminators" = problem
# Fix line endings
sed -i 's/\r$//' start.sh
# Or in Dockerfile
RUN sed -i 's/\r$//' /app/start.shEnsure shebang matches available shell:
#!/bin/sh # Works in Alpine
#!/bin/bash # Requires bash installationExit code 127 in multi-stage builds usually means COPY --from failed silently or copied to the wrong path. Verify each stage:
# Debug by listing files in final stage
RUN ls -la /usr/local/bin/Volume mounts can shadow directories containing binaries. If /app is mounted as an empty volume, anything originally in /app becomes inaccessible.
For architecture mismatches (AMD64 image on ARM node), the binary may exist but fail to execute. Check with:
kubectl get nodes -o wide # Shows architecture
docker inspect myimage:latest | grep ArchitectureUse multi-arch images or ensure node selector matches image architecture.
No subnets found for EKS cluster
How to fix "eks subnet not found" in Kubernetes
unable to compute replica count
How to fix "unable to compute replica count" in Kubernetes HPA
error: context not found
How to fix "error: context not found" in Kubernetes
default backend - 404
How to fix "default backend - 404" in Kubernetes Ingress
serviceaccount cannot list resource
How to fix "serviceaccount cannot list resource" in Kubernetes