Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the numeric exit status of an exited docker container?

When a container exits, docker ps -a shows its exit code (scroll

$ docker run ubuntu bash -c "exit 1" CONTAINER ID   IMAGE    COMMAND              CREATED        STATUS                     PORTS                     NAMES c2c769c4b9ef   ubuntu   "bash -c 'exit 1'"   6 seconds ago  Exited (1) 3 seconds ago                             happy_fermat 

How do I get the numeric exit code programmatically, without error-prone grep-ing and cut-ing?

like image 361
Adam Matan Avatar asked Sep 19 '17 12:09

Adam Matan


2 Answers

Use docker inspect with templates:

$ docker inspect c2c769c4b9ef --format='{{.State.ExitCode}}' 1 
like image 125
Adam Matan Avatar answered Sep 25 '22 16:09

Adam Matan


You can use echo:

$ docker run debian bash -c "exit 1" $ echo $? 1  $ docker run debian bash -c "exit 0" $ echo $? 0 
like image 25
noamt Avatar answered Sep 21 '22 16:09

noamt