Exit code 126 means the command was found but cannot be executed, typically due to missing execute permissions. Add chmod +x to your Dockerfile or fix file permissions.
Exit code 126 indicates that the specified command exists but cannot be executed. This is distinct from exit code 127 (command not found). The most common cause is missing executable permissions on scripts or binaries. In containerized environments, this typically happens when shell scripts are copied into the image without the execute bit set, or when the container runs as a user without permission to execute the specified command.
Get the specific error message:
kubectl logs <pod-name>
kubectl logs <pod-name> --previousLook for messages like:
- "/entrypoint.sh: Permission denied"
- "cannot execute binary file"
- "Operation not permitted"
The error message identifies which file lacks permissions.
Ensure scripts are executable in your image:
# Copy and set permissions
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Or copy with permissions preserved (if source has +x)
COPY --chmod=755 entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]Rebuild and push the image:
docker build -t myimage:latest .
docker push myimage:latestBefore building, ensure the script has execute permissions:
ls -la entrypoint.sh
# Should show: -rwxr-xr-x
# If not executable, add permission:
chmod +x entrypoint.sh
git add entrypoint.sh
git commit -m "Add execute permission to entrypoint"Note: Git preserves the execute bit, but some workflows strip it.
Exit code 126 can occur if the script's interpreter isn't available:
# Wrong - bash not in Alpine images
#!/bin/bash
# Correct for Alpine
#!/bin/shVerify the interpreter exists in your image:
docker run --rm myimage:latest which sh
docker run --rm myimage:latest which bashInstall bash if needed: RUN apk add --no-cache bash
If the main container won't start, use a debug approach:
# Temporarily override to keep container running
command: ["sleep", "infinity"]Then exec in and test:
kubectl exec -it <pod-name> -- /bin/sh
# Check file permissions
ls -la /entrypoint.sh
# Try to execute
/entrypoint.shThe container user may lack execute permissions:
securityContext:
runAsUser: 1000
runAsGroup: 1000Ensure the file is executable by that user:
# Make executable by all users
RUN chmod 755 /entrypoint.sh
# Or change ownership
RUN chown 1000:1000 /entrypoint.sh && chmod +x /entrypoint.shOn Windows, the execute bit isn't preserved in the same way as Linux. If developing on Windows and building images:
- Use git config core.fileMode true to track permission changes
- Add explicit RUN chmod +x in Dockerfile regardless of source permissions
For kubectl cp failures with exit code 126, ensure tar is installed and executable in the container. Many minimal images don't include tar:
RUN apk add --no-cache tar # Alpine
RUN apt-get update && apt-get install -y tar # DebianOCI runtime errors showing exit code 126 may indicate SELinux or AppArmor denying execution. Check node-level security policies if container-level permissions appear correct.
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