0 0 Share PDF

What is the difference between dead and exited containers?

Article ID: KB000589

While reviewing the output of docker ps -a you may have seen both dead and exited statuses for containers. How are these different?

Exited Container

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 STATUS column:

# docker run --name hello alpine echo 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 Container

In contrast, dead containers are in a defunct state, typically due to issues with accessing their underlying storage.

An example which will create a dead container:

  1. Create a simple container. (e.g, docker run -d alpine sleep 100)
  2. Stop the container.
  3. Make the underlying storage of the container immutable. (e.g, on Linux this can be done with chattr)
  4. Remove the container with docker rm <container ID>.

These steps will leave the container in a dead state.

Note: Causes of dead containers are not limited to the above example.

More information on container statuses can be found in the Docker docs.