What is the authoritative list of Docker Run exit codes?
Asked Answered
C

2

93

Apologies if this has been asked, but nowhere in the Docker documentation can I find an authoritative list of exit codes (also called exit status). Surprising! I see suggestions about making it consistent, but no docs on docker.com.

Does anyone know where the exit codes can be found?

Cocytus answered 8/7, 2015 at 15:49 Comment(2)
in the source code ?Nepean
I'm very sorry if I was unclear. What about errors? For example if I docker run -v non_existent_directory or perhaps docker run improper_container_path There is a lot that can go wrong, and the exit code should reflect this.Cocytus
S
117

For Docker >= 1.10 see this PR, which follows standard chroot exit codes:

  • 125: docker run itself fails
  • 126: contained command cannot be invoked
  • 127: if contained command cannot be found
  • 128 + n Fatal error signal n:
    • 130 = (128+2) Container terminated by Control-C
    • 137 = (128+9) Container received a SIGKILL
    • 143 = (128+15) Container received a SIGTERM

Check the man page of signal for the full list (on cmd type man 7 signal or check online e.g. signal).

Check Docker's exit status documentation for more information about the current version.

Serving answered 15/2, 2016 at 13:45 Comment(3)
And with that PR the docs were also updated: docs.docker.com/engine/reference/run/#/exit-statusStream
“128 + n” — I don’t see any evidence in either the referenced PR or docs that there is any such handling.Response
@AndrewMarshall That's pretty standard. E.g., in man bash: "The return value of a simple command is its exit status, or 128+n if the command is terminated by signal n".Crestfallen
R
19

Normally it will be the exit status of the process, so it's application dependent i.e:

$ docker run debian sh -c "exit 5;"
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
7fcc37778df0        debian              "sh -c 'exit 5;'"   4 seconds ago       Exited (5) 3 seconds ago                       reverent_einstein   

But in certain cases Docker itself can return an exit code:

  • 125 if the Docker daemon has an error (e.g. a wrong flag is provided)
  • 126 if the container command can't be invoked (e.g. file isn't executable)
  • 127 if the container command can't be found (e.g. wrong path to binary)

https://docs.docker.com/engine/reference/run/#exit-status

Roemer answered 8/7, 2015 at 17:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.