While reviewing the output of
docker ps -a you may have seen both
exited statuses for containers. How are these different?
An exited container is a normal state for a container, when the main process running in it has exited. Normally a graceful exit is expected, as you would expect when running a short-lived program such as
ls or after a long-running program such as
nginx has received a signal to gracefully shut down. In those cases, you would see something such as
Exited (0) along with how long ago it exited under the
# docker run --name hello alpine echo hello hello # docker ps -af name=hello CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 43038e88d786 alpine "echo hello" 6 seconds ago Exited (0) 5 seconds ago hello
The above example is a graceful (zero) exit.
The following example shows a non-zero exit:
# docker run --name whoops alpine false # docker ps -af name=whoops CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 08b0417182cf alpine "false" 11 seconds ago Exited (1) 10 seconds ago whoops
dead containers are in a defunct state, typically due to issues with accessing their underlying storage.
An example which will create a dead container:
- Create a simple container. (e.g,
docker run -d alpine sleep 100)
- Stop the container.
- Make the underlying storage of the container immutable. (e.g, on Linux this can be done with
- Remove the container with
docker rm <container ID>.
These steps will leave the container in a
Note: Causes of
deadcontainers are not limited to the above example.
More information on container statuses can be found in the Docker docs.