Exit Code 126
DockerERRORCriticalStartupHIGH confidence

Contained command cannot be invoked

What this means

This exit code signifies that the command specified in the container's CMD or ENTRYPOINT could not be executed because it lacks execute permissions. It's a file system permission issue within the container image itself.

Why it happens
  1. 1The script or binary specified as the container's entrypoint does not have the execute bit (+x) set.
  2. 2The file system was mounted with the 'noexec' option, preventing execution of any binaries.
  3. 3The script has the wrong shebang line (e.g., `#!/bin/sh ` with Windows line endings).
  4. 4The binary is compiled for the wrong architecture (e.g., ARM binary on an x86 host).
How to reproduce

A Dockerfile copies a shell script but fails to give it execute permissions.

trigger — this will error
trigger — this will error
# Dockerfile
FROM alpine
WORKDIR /app
COPY start.sh .
# Missing: RUN chmod +x start.sh
ENTRYPOINT ["./start.sh"]

# start.sh (without execute permission)
#!/bin/sh
echo "Hello, World!"

expected output

OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "./start.sh": permission denied: unknown

Fix 1

Add Execute Permissions in Dockerfile

WHEN When the entrypoint is a script you control.

Add Execute Permissions in Dockerfile
# Add this layer to your Dockerfile before the CMD or ENTRYPOINT
RUN chmod +x your-script.sh

Why this works

This sets the execute bit for the script within the image file system, making it runnable.

Fix 2

Use 'sh' to Run the Script

WHEN You cannot modify the Dockerfile or file permissions easily.

Use 'sh' to Run the Script
# Modify the ENTRYPOINT or docker run command
ENTRYPOINT ["sh", "./your-script.sh"]

Why this works

This invokes the shell ('sh') executable, which is runnable, and instructs it to interpret and execute your script, bypassing the script's own execute permission.

What not to do

Set 'chmod 777' on all files.

This makes files world-writable, creating a security vulnerability. Only grant the minimum required permissions (e.g., 'chmod +x' or 'chmod 755').

Sources
Official documentation ↗

Linux man-pages: execve(2)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Docker errors