What Docker's Exited(code) Statuses Mean: 125, 126, 127, 128, 130, 137, 143

Exited just means the container has stopped. The argument is always about the number that follows — 125, 126, 127, 128, 130, 137, 143. Here's where those numbers actually come from.

This post started with someone in a developer group asking what Docker’s Exited (143) status meant. We got into the discussion below — if you want to join the group too, the QR codes are at https://www.renfei.net/about/#shequn. I went and dug into where these status codes actually come from and what each one means.

Everyone agrees that Exited means the container has exited and finished. The disagreement is always about the code that follows: 125, 126, 127, 128, 130, 137, 143. So I went and researched where those numbers come from.

Where Exited(code) Came From

The story goes all the way back to June 28, 2014, when rhatdan opened an issue: docker run exit code consisency #6734. He felt Docker’s exits gave you no way to tell what went wrong, so he proposed exposing an exit code, and suggested following the chroot standard. bgrant0607 thought it should be consistent with shell exit codes instead, pointing at Appendix E. Exit Codes With Special Meanings in the Bash scripting guide.

Finally, on June 18, 2015, sallyom opened a PR: Change ‘docker run’ exit codes to distinguish docker/contained errors #14012. After another round of discussion it was merged into master by maintainer thaJeztah on November 5, 2015, and Docker 1.10 shipped with those changes.

Exit Status in the Official Docs

The official docs describe exit status too — see https://docs.docker.com/engine/reference/run/#exit-status. There are four cases:

  • 125: caused by the Docker daemon itself, usually because the docker run command errored out on its own.

  • 126: the contained command cannot be invoked — for example insufficient permissions, or not being able to access a directory or execute the command.

  • 127: the contained command cannot be found — for example curl isn’t installed in the environment but you called curl, so there’s nothing to find.

  • Anything else: a signal raised by the program inside.

The Codes in the Bash Scripting Guide

As mentioned above, someone suggested staying consistent with the shell, so the Bash guide was the other reference — see https://tldp.org/LDP/abs/html/exitcodes.html. Besides the three documented by Docker, there’s one special case worth mentioning: 128+N. Since 126 through 128 are already taken, whatever’s left has to start at 128 and go up, hence 128+N, where N is the Linux signal number. I talked about Linux signals in another post, What Do kill, kill -9 and kill -3 Mean in Linux, and How Do They Differ? — worth a read. If the signal is 15, then 128+15=143, and Docker’s exit code becomes Exited(143). Pretty straightforward, right?

One more thing the manual spells out: the number can’t exceed 255. Anything above 255 gets taken modulo — i.e. the remainder. 3809 is greater than 255, so 3809 % 256 = 225, and it becomes 225, giving you a wrong code. But that’s Docker’s problem to worry about, not ours — unless you want to define your own exit signal.