Exit code 127 indicates that a command specified in your Docker container could not be found. This is a standard Linux/Unix shell error code meaning the shell cannot locate the executable you're trying to run.
Exit code 127 is a standard POSIX/Linux shell exit code that means "command not found." When Docker reports this error, it means the container started but the command specified in CMD, ENTRYPOINT, or the docker run command does not exist or cannot be located in the container's filesystem. This error originates from the shell inside the container, not from Docker itself. The container's shell (typically /bin/sh or /bin/bash) tried to execute a command but couldn't find the binary in the PATH or at the specified location. Common scenarios include: specifying a command that isn't installed in the base image, using the wrong path to an executable, or having scripts with incorrect line endings (Windows CRLF vs Unix LF).
Run the following command to see what command failed:
docker logs <container_name_or_id>Look for messages like "command not found" or "No such file or directory" to identify which specific command is missing.
Run an interactive shell in your container to check if the command exists:
docker run -it --entrypoint /bin/sh <image_name>Then try running the command manually. If it's not found, you need to install it in your Dockerfile.
Review your Dockerfile for typos or incorrect paths:
# Correct - use absolute paths
CMD ["/usr/local/bin/myapp"]
# Incorrect - relative path may fail
CMD ["myapp"]Use which <command> or type <command> inside the container to find the correct path.
If the command isn't available, add it to your Dockerfile. Use the correct package manager for your base image:
# For Debian/Ubuntu-based images
RUN apt-get update && apt-get install -y <package_name>
# For Alpine-based images
RUN apk add --no-cache <package_name>
# For RHEL/CentOS-based images
RUN yum install -y <package_name>If you're developing on Windows, your shell scripts might have CRLF line endings. Convert them to LF:
# Using dos2unix
dos2unix your-script.sh
# Or in your Dockerfile
RUN sed -i 's/\r$//' /app/your-script.shAlternatively, configure Git to not convert line endings:
git config --global core.autocrlf inputMake sure your script starts with a valid shebang line and has execute permissions:
#!/bin/bash
# or for Alpine which uses ash by default:
#!/bin/shIn your Dockerfile, ensure the script is executable:
COPY script.sh /app/
RUN chmod +x /app/script.shTo diagnose which exact command is failing, enable shell tracing:
# Temporarily modify your CMD for debugging
CMD ["/bin/sh", "-x", "/app/entrypoint.sh"]The -x flag shows each command before execution, helping identify the failing command.
Multi-stage builds and missing binaries: If using multi-stage builds, ensure you copy all required binaries and their dependencies to the final stage. Use ldd <binary> to list shared library dependencies.
Alpine Linux gotchas: Alpine uses musl libc instead of glibc. Binaries compiled for glibc-based systems won't work on Alpine. Either compile statically, use Alpine-compatible builds, or switch to a glibc-based image.
Debugging in Kubernetes: If the container crashes too quickly to inspect, change the command temporarily:
command: ["sleep", "infinity"]Then exec into the pod to debug.
Using exec form vs shell form: The exec form CMD ["executable", "param1"] runs the command directly. The shell form CMD command param1 runs through /bin/sh -c, which requires /bin/sh to exist in the image.
image operating system "linux" cannot be used on this platform
How to fix 'image operating system linux cannot be used on this platform' in Docker
manifest unknown: manifest unknown
How to fix 'manifest unknown' in Docker
cannot open '/etc/passwd': Permission denied
How to fix 'cannot open: Permission denied' in Docker
Error response from daemon: failed to create the ipvlan port
How to fix 'failed to create the ipvlan port' in Docker
toomanyrequests: Rate exceeded for anonymous users
How to fix 'Rate exceeded for anonymous users' in Docker Hub