Sub topic 1
Container states: created, running, restarting, paused, exited, dead
Every container is in exactly one state at any moment. The state is the first clue in a debugging session, because it narrows where to look next. This chapter covers what each state means and which command shows it.
Prerequisites
This chapter assumes you can do the following:
- Run
docker run,docker build, anddocker ps. - Use a Linux shell.
- Explain what a process and a signal are.
- Explain the difference between a Dockerfile
ENTRYPOINTandCMD.
How the states connect
A container is a configured process with its own filesystem and namespaces. Its state describes what the daemon knows about that main process (PID 1 inside the container).
What each state means when debugging
| State | Meaning | What to suspect |
|---|---|---|
| created | The container exists but its process has not started. | A start failure, such as a bad mount, a missing command, or a port conflict. Check the daemon error. |
| running | PID 1 is alive. | The process is up, but it may still be unhealthy or stuck. Check logs and health. |
| restarting | The restart policy is waiting to start the container again. | A crash loop. |
| paused | All processes are frozen with the cgroup freezer. | Someone ran `docker pause`. The container will not respond to anything. |
| exited | PID 1 has stopped. | Read the exit code and the logs. |
| dead | The daemon failed to remove the container completely. | A storage or mount problem. The container cannot be restarted. |
Some start failures leave a container in created instead of exited. The failure happens before your program runs, so the logs are empty. The reason is in State.Error.
Reading the state
List every container, including stopped ones, with its state:
docker ps -a --format 'table {{.Names}}\t{{.State}}\t{{.Status}}'State is the single-word state. Status is the human-readable text, such as Up 3 minutes or Exited (1) 2 hours ago.
Filter by state when the list is long:
docker ps -a --filter status=deadFor one container, docker inspect gives the exact fields:
docker inspect --format 'status={{.State.Status}} running={{.State.Running}} paused={{.State.Paused}} restarting={{.State.Restarting}}' webThe flags overlap. A paused container has running=true and paused=true. A restarting container also reports running=true. Use .State.Status for the real answer.
Cleaning up dead containers
A dead container cannot be started again. Try removing it with docker rm. If that fails, the error usually names a busy mount or a storage driver problem. Fix the cause, or restart the Docker daemon, and then remove the container.
Exercise
A container shows Created in docker ps -a, and docker logs prints nothing. Which field do you inspect next, and why?
Show answer
Inspect .State.Error, for example with docker inspect --format '{{.State.Error}}' NAME. The container never started its process, so it wrote no logs. The daemon or runtime records the reason the start failed in that field.