DockerJunior

docker run exit codes 125, 126, 127 and 137: what each one means

Docker uses exit codes 125, 126 and 127 for its own failures and passes the container's code through otherwise. Read the code before you read the logs.

What you see

  • docker: Error response from daemon: Container command 'foo' not found or does not exist.
  • docker: Error response from daemon: Container command '/etc' could not be invoked.
  • flag provided but not defined: --foo
  • A container with exit code 137

What it means

The exit code from docker run tells you where the failure happened. Per the Docker docs: 125 means the error is with the Docker daemon itself, 126 means the contained command can't be invoked, and 127 means the contained command can't be found. Any other code is the exit code of the command inside the container.

Codes above 128 follow the Unix convention of 128 plus a signal number. 137 is 128 + 9, SIGKILL, and 143 is 128 + 15, SIGTERM. That convention comes from the general Unix model, not the Docker docs, so confirm with the OOM flag below before you blame memory.

How to confirm the cause

  1. 1
    Read the code and the OOM flag together
    docker inspect --format '{{.State.ExitCode}} oom={{.State.OOMKilled}}' CONTAINER

    oom=true with 137 means the kernel killed it for memory. 137 with oom=false usually means someone or something sent SIGKILL, for example docker kill or a stop that timed out.

  2. 2
    Read the first error in the logs
    docker logs --tail 50 CONTAINER

    Read the first error, not the last. Later lines are often fallout.

  3. 3
    For 126 and 127, check the command and the image contents
    docker run --rm --entrypoint sh IMAGE -c 'ls -l /path/to/command; which command'

    Needs a shell in the image. For a minimal image, check the path in the Dockerfile COPY and ENTRYPOINT lines instead.

Causes and fixes

  • 125: Docker itself failed

    HOW TO TELL
    The message is about a flag or the daemon, not your program. The docs' example is flag provided but not defined: --foo.
    ROOT CAUSE
    The docker run command was malformed, or the daemon could not start the container at all.
    FIX
    Fix the command line. Run docker run --help to check the option.
  • 126: the command is not executable

    HOW TO TELL
    Container command ... could not be invoked.
    ROOT CAUSE
    The path exists but is not something the container can run: a directory, a file without the execute bit, or the wrong format for the platform.
    FIX
    Add execute permission when you copy the file, for example RUN chmod +x /app/start.sh, and check the file is a script or binary for this platform.
  • 127: the command is not found

    HOW TO TELL
    Container command 'foo' not found or does not exist.
    ROOT CAUSE
    The CMD or ENTRYPOINT names a file that is not in the image, or is not on PATH. A bad COPY path or a multi-stage build that forgot to copy the binary are common.
    FIX
    Check the Dockerfile COPY paths and the command, then rebuild. Use the absolute path to be sure.
  • 137: killed by SIGKILL

    HOW TO TELL
    Exit code 137 and oom=true, or oom=false after a stop.
    ROOT CAUSE
    With oom=true, the container hit its memory limit and the kernel OOM killer ended it. With oom=false, docker stop sent SIGTERM, waited out the grace period, then sent SIGKILL because the app did not exit in time.
    FIX
    For OOM, raise --memory or fix the leak. For a slow stop, make the app handle SIGTERM and exit promptly.

How to stop it coming back

  • Test the container's entrypoint in CI with the exact command you deploy.
  • Handle SIGTERM in the app so stops are clean.
  • Set a memory limit and alert on OOM kills.

Keep going

Sources

Docker documentation (docs.docker.com), read 18 Nov 2026 from the official docs repository.

Search

Search cheat sheets and projects