brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: docker run exit codes 125, 126 and 127 tell you who failed

Docker
~/tips/tip-docker-run-exit-codes-125-126-127

docker run busybox foo; echo $?

Explains what exit codes 125, 126 and 127 mean when docker run fails to start a command.

When a docker run fails, the first question is whether Docker or your command is to blame. The exit code answers it before you read any logs.

The docs describe three special codes. 125 means the error is with the Docker daemon itself, for example an unknown flag. 126 means the command inside the container exists but cannot be invoked. 127 means the command cannot be found. Any other code is the exit code of the container command itself.

docker run busybox foo; echo $?
docker: Error response from daemon: Container command 'foo' not found or does not exist.
127
docker run busybox /etc; echo $?
docker: Error response from daemon: Container command '/etc' could not be invoked.
126

So 127 usually means a typo, a missing binary or a wrong --entrypoint, and 126 often means a file that is not executable or a folder given where a program should be. A 125 sends you to the flags: run docker run --help and read what you typed. Anything else, like the 3 from docker run busybox /bin/sh -c 'exit 3', comes from the application, and then docker logs is where to look.

The app can use these numbers too. A script inside the container that ends with exit 127 looks the same as a missing command, so check the error message that Docker prints next to the code, as in the examples above.

Further reading: Docker run: exit status

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link