Observe the exit code from docker container wait
In this final step, we will examine the exit code that was printed by the docker container wait
command in the first terminal.
Switch back to the first terminal window where you ran the docker container wait <container_id>
command.
You should see a number printed on the line after the command. This number is the exit code of the container.
137
In the previous step, you stopped the container using docker stop
. When a container is stopped using docker stop
, Docker sends a SIGTERM
signal to the main process in the container, and after a grace period, a SIGKILL
signal if the process hasn't exited. An exit code of 137
is a common indicator that a process was terminated by a SIGKILL
signal (128 + 9, where 9 is the signal number for SIGKILL
).
This demonstrates that docker container wait
not only waits for the container to stop but also provides the exit code, which can give you information about how the container stopped. If the container had finished its sleep 30
command naturally, the exit code would have been 0
.
You can verify the container is stopped by running docker ps -a
in either terminal. The -a
flag shows all containers, including stopped ones.
docker ps -a
You should see your alpine
container listed, and its status should be Exited (<exit_code>)
.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
<container_id> alpine "sleep 30" X minutes ago Exited (137) X seconds ago <container_name>
This concludes the lab on using docker container wait
. You have learned how to start a container in the background, wait for it to stop using docker container wait
, stop it from another terminal, and observe the resulting exit code.