Sub topic 1
Container states: created, running, restarting, paused, exited, dead
Every debugging session starts with one question: what state is the container in? The state tells you which tools can help. You can't docker exec into an exited container, and logs from a container stuck in created will be empty. This chapter covers the six states, how a container moves between them, and how to read them from the command line.
Prerequisites
This chapter assumes you have:
- Basic Docker usage: images,
docker run, anddocker build. - Comfort with a Linux shell and commands such as
ls,cat, andps. - A basic idea of Linux processes and signals, such as the difference between SIGTERM and SIGKILL.
- Familiarity with
ENTRYPOINTandCMDin a Dockerfile.
You need a working Docker Engine and permission to run docker commands. The examples use the small alpine:3.20 image.
What a state describes
A container is a process (or a small tree of processes) with its own namespaces and cgroup limits, plus metadata the daemon keeps about it. The state describes the daemon's view of that main process. It does not describe whether your application works. A container can be running while the application inside it returns errors on every request.
Docker reports six states in normal use: created, running, restarting, paused, exited, and dead. The daemon also has a short-lived removing state while a container is being deleted. You will rarely see it.
The six states
created
The daemon has built the container's configuration and writable layer, but the main process has never run. docker create produces this state on purpose.
You also see created when docker run or docker start fails before your process launches. Common causes are a host port that is already allocated, a bind-mount source that cannot be used, or a runtime error such as an entrypoint that cannot be executed. In that case the container stays in created and the reason is in .State.Error.
A container in created has no logs, because nothing ran. Read the error message instead.
running
The main process (PID 1 inside the container) is alive. This is the only state where docker exec works. Logs are being written, and docker stats shows live numbers.
running means only that the process exists. It says nothing about readiness. If a service is up but not answering, you need a health check (covered in a later chapter) or a probe from inside the container.
restarting
The container exited and its restart policy told the daemon to start it again. The container sits in restarting during the delay between attempts. The daemon increases that delay after repeated failures, starting at 100 ms and doubling up to a cap.
If you see restarting repeatedly, you have a crash loop. Look at the previous exit code and the logs from the last attempt. You can't docker exec into a restarting container, because the process is not alive at that moment.
paused
All processes in the container are frozen with the cgroup freezer. docker pause does not send a signal, so the application cannot react to it. Memory stays allocated and network connections stay open. Clients on the other end of those connections see timeouts.
A forgotten pause is an easy misdiagnosis, because the container looks alive in docker ps. Check the status text for (Paused).
exited
The main process ended, either by itself or because it was stopped. The exit code is kept in the container metadata. The container's filesystem and logs also remain until you remove it, so this state is where post-mortem work happens.
docker stop sends SIGTERM, waits 10 seconds by default, then sends SIGKILL. An application that ignores SIGTERM therefore exits with code 137 after the grace period. Exit codes get their own chapter.
dead
The daemon tried to remove the container and failed partway, for example because a mount was busy or a storage driver call failed. A dead container cannot be started again. The only useful action is to remove it, often after fixing the underlying problem and sometimes after restarting the daemon.
Dead containers are rare. If you meet one, look at the daemon logs for the removal error.
Reading state from the command line
Start with the list. The -a flag matters, because docker ps without it hides everything that is not running.
docker ps -a --format 'table {{.Names}}\t{{.Status}}\t{{.Image}}'The STATUS column mixes the state with extra detail:
| STATUS text | State | What it tells you |
|---|---|---|
| `Created` | created | Never started, or failed to start |
| `Up 5 minutes` | running | Uptime since the last start |
| `Up 5 minutes (Paused)` | paused | Frozen, not stopped |
| `Up 5 minutes (unhealthy)` | running | Health check is failing, state is still running |
| `Restarting (1) 12 seconds ago` | restarting | Last exit code was 1, waiting for the next attempt |
| `Exited (137) 2 minutes ago` | exited | Exit code 137, ended two minutes ago |
| `Dead` | dead | Removal failed, can only be removed |
Notice that unhealthy is not a state. It is a separate health result shown beside the running state.
To filter by state, use --filter status=. The accepted values are created, restarting, running, removing, paused, exited, and dead.
docker ps -a --filter status=restarting
docker ps -a --filter status=deadFor scripts and exact answers, use docker inspect. The .State.Status field holds the state as one word.
docker inspect --format 'status={{.State.Status}} exit={{.State.ExitCode}} oom={{.State.OOMKilled}} error={{.State.Error}}' webPrefer .State.Status over the boolean fields. .State.Running stays true for a paused container and during a restart wait, so it can mislead you.
Walking through the states
This sequence uses a throwaway container so you can watch each transition. Run it as shown.
docker create --name demo alpine:3.20 sleep 300
docker inspect --format '{{.State.Status}}' demo
docker start demo
docker inspect --format '{{.State.Status}}' demo
docker pause demo
docker inspect --format '{{.State.Status}}' demo
docker unpause demo
docker kill demo
docker inspect --format 'status={{.State.Status}} exit={{.State.ExitCode}}' demo
docker rm demoThe commands print created, running, paused, and finally status=exited exit=137. The exit code is 137 because docker kill sends SIGKILL, and a process killed by signal 9 reports 128 + 9.
To see restarting, run a container that always fails and has a restart policy:
docker run -d --name flaky --restart=on-failure alpine:3.20 sh -c 'echo starting; exit 1'
sleep 3
docker ps -a --filter name=flaky --format '{{.Names}}\t{{.Status}}'
docker inspect --format 'status={{.State.Status}} restarts={{.RestartCount}} exit={{.State.ExitCode}}' flaky
docker rm -f flakyRun the docker ps line a few times and you will see the status alternate between Restarting (1) and Up, while RestartCount climbs.
What each state implies for debugging
| State | Logs available | `docker exec` | First thing to check |
|---|---|---|---|
| created | No | No | `.State.Error`, then ports, mounts, entrypoint |
| running | Yes | Yes | Logs, health, resource use |
| restarting | Yes, from past runs | No | Exit code and logs of the last attempt |
| paused | Yes, but no new output | No | Whether someone ran `docker pause` |
| exited | Yes | No | Exit code, `OOMKilled`, last log lines |
| dead | Usually | No | Daemon logs, then `docker rm` |
The pattern is: if the process is not alive, move to evidence the container left behind (logs, exit code, filesystem). If it is alive, you can look inside.
Common mistakes
- Forgetting
-a. A container that crashed instantly disappears fromdocker ps, and people conclude it never started. - Treating
runningas healthy. The state reflects the process, not the service. - Looking for logs in
created. Nothing ran. Read.State.Error. - Trying to restart a dead container. It cannot be started. Remove it.
- Using
--rmand then wanting a post-mortem. The container is deleted as soon as it exits, along with its state and exit code. Drop--rmwhile debugging.
Exercises
Exercise
A container shows Up 10 minutes (Paused) in docker ps. Its application stopped answering requests, but the logs show no errors. What is the likely cause, and which command fixes it?
Show answer
Someone ran docker pause, which froze every process with the cgroup freezer. The application did not crash and had no chance to log anything. Run docker unpause NAME to resume it.
Exercise
docker run -d -p 8080:80 myapp fails with a "port is already allocated" error, and docker ps -a lists the container. What state is it most likely in, why is docker logs empty, and where do you find the reason?
Show answer
It is most likely in created. The daemon built the container but could not start it, so the main process never ran and there is nothing to log. The reason is in .State.Error, which you can read with docker inspect --format '{{.State.Error}}' NAME.
Exercise
You run the flaky example above. docker inspect shows status=restarting restarts=4. Why can't you use docker exec to investigate, and what two sources of evidence should you use instead?
Show answer
A restarting container has no live process at that moment, and docker exec needs a running one. Use docker logs for output from the earlier attempts, and read .State.ExitCode (and .State.OOMKilled) to see how the last attempt ended.