The Docker container lifecycle is the journey every container takes, from creation through running, stopping and removal. A container starts as an image, becomes a running process, and ends when it is stopped and removed, with its writable layer deleted unless its data was stored in a volume. The short answer is that understanding this lifecycle means knowing the handful of states a container can be in, the commands that move it between them, and the one rule that matters most: containers are disposable, so anything worth keeping must live outside them.
Docker introduced containers to mainstream development with its first public release in 2013, and the lifecycle has stayed deliberately simple since then. A container is a running instance of an image, isolated from other processes on the same host but sharing the host kernel. Our Kubernetes tutorial shows where containers go next, once a single host is no longer enough.
Key takeaways
- The Docker container lifecycle has five main states: created, running, paused, stopped and removed, plus the restarting state during recovery.
- An image is a read-only template; a container adds a thin writable layer that disappears when the container is removed.
- Restart policies decide what happens when a container exits or its host reboots, and they belong in the run command or Compose file.
- Health checks tell Docker whether the application inside the container is actually working, not just running.
- Data that must survive a container belongs in a named volume; everything else can be recreated from the image.
The five states of a container
Every container is always in one state. It is created when Docker builds its filesystem from the image and reserves its resources, but the application inside has not started yet. It becomes running when the main process starts, and it stays running until that process exits, the container is stopped, or it is killed. A running container can be paused, which freezes its processes without stopping them, and unpaused to resume exactly where it left off.
When the main process exits, the container becomes stopped, keeping its filesystem and logs available for inspection until it is removed. Removal deletes the container and its writable layer, while the image remains for the next run. There is also a restarting state, which Docker enters when a container with a restart policy exits unexpectedly and Docker is trying to start it again. Best for: anyone learning Docker, because the state model explains almost every command you will run.
| State | What it means | How to get there |
|---|---|---|
| Created | Filesystem built, process not started | docker create, or the first half of docker run |
| Running | Main process is executing | docker start, or docker run |
| Paused | Processes frozen, memory held | docker pause |
| Stopped | Process exited, filesystem kept | docker stop, or the process exits |
| Removed | Container and writable layer deleted | docker rm |
| Restarting | Docker is retrying a failed container | Automatic, under a restart policy |
Create and run: how a container is born
Running a container is usually one command, but it does two jobs. The docker run command first creates the container from the image, setting up its filesystem layers, network and configuration, and then starts it. The docker create command does only the first half, which is useful when you want to prepare a container and start it later, or copy files into it before its process begins.
Most of a container’s behaviour is decided at creation, not at start. The port mappings, volume mounts, environment variables and network are fixed when the container is created, so changing them means removing the container and creating a new one. This is not a limitation in practice, because containers are cheap to recreate, and it is why configuration belongs in the run command or Compose file rather than in manual changes inside a running container. Best for: developers who want predictable containers that can be recreated exactly from a command or a file.
Running: what happens while a container lives
While a container runs, its main process is the container. Docker monitors that single process, and when it exits, the container stops, whatever else was happening inside. This is why the command in a Dockerfile should run the application in the foreground: a process that forks into the background and exits immediately will stop the container at once, which is one of the most common beginner surprises.
A running container writes its output to its logs, which you read with docker logs, and it writes files to its writable layer, which is fast but temporary. It can also be inspected live with docker exec, which opens a shell inside it, and its resource use can be watched with docker stats. None of this changes the container’s definition: a running container is the image plus its configuration plus whatever it has written since it started. Best for: long-running services such as web servers and databases, which stay in this state for days or weeks.

Pause, stop and kill
Pausing and stopping are different tools for different jobs. Pausing freezes a container’s processes with the SIGSTOP signal, holding its memory and state so it can resume instantly, which is handy for briefly freeing CPU without losing work. Stopping sends SIGTERM first, giving the process a short grace period, by default ten seconds, to shut down cleanly, and then sends SIGKILL if it is still running.
The distinction matters for databases and other stateful applications, which need that grace period to flush data to disk. A container that is killed without warning can leave corrupted data, which is one more reason to keep important data in a volume and to give applications a proper shutdown path. When a container misbehaves and will not stop, docker kill ends it immediately, but treat that as a last resort rather than a routine. Best for: operators who need to control containers safely, especially ones holding state.
Restart policies: surviving crashes and reboots
A restart policy tells Docker what to do when a container exits. The no policy never restarts it, which is the default and the right choice for one-off tasks. The always policy restarts it whenever it stops, including after the host reboots, which suits long-running services. The unless-stopped policy behaves the same, except it respects a manual stop, so a container you stopped deliberately stays stopped after a reboot.
The on-failure policy restarts only when the container exits with a non-zero code, which suits batch jobs and workers that should retry after a crash but not after a clean finish. Restart policies are a single-host safety net, not a replacement for orchestration: they restart a container on the same machine, and they cannot move it to a healthy host if the machine itself fails. For that, you need an orchestrator, as our guide to container orchestration explained describes. Best for: services on a single host that must come back on their own after a crash or a reboot.
Health checks: is it running, or is it working?
A running container is not necessarily a working application. A web server process can be alive while its database connection is broken, and Docker would report it as running either way. A health check fixes this by running a small test inside the container at intervals, such as requesting the application’s own health endpoint, and marking the container healthy or unhealthy based on the result.
Health checks change how other tools treat the container. Docker Compose can wait for a dependency to become healthy before starting the next service, so a web application no longer tries to connect to a database that is still starting up. Orchestrators use the same idea at larger scale, restarting containers that fail their checks. Keep health checks fast and lightweight, because a slow or flaky check creates more problems than it solves. Best for: any service with dependencies, where starting order and failure detection matter.
Removal and cleanup
Removal is the end of the lifecycle, and it is also the moment when data loss happens. The docker rm command deletes the container and its writable layer, so anything written inside the container that was not stored in a volume is gone. The image is not affected, and a new container from the same image starts fresh, which is exactly how it should work for stateless services.
Stopped containers, unused images and orphaned volumes accumulate quietly, and Docker’s disk usage grows with them. The docker system prune command clears stopped containers, unused networks and dangling images in one pass, and adding the volume flag also removes unused volumes, so use it carefully. A weekly prune is enough for most development machines, and it is far better than discovering a full disk during a deployment. Best for: keeping a development machine or a single-host server tidy without losing data you meant to keep.
Lifecycle checklist
- Give every container a restart policy that matches its job, and never rely on the default for a service.
- Add a health check to any service other services depend on, so failures are detected early.
- Store data that must survive in a named volume, and treat anything else as disposable.
- Set a stop timeout that gives stateful applications time to shut down cleanly.
- Tag images with a version, so a removed container can be recreated exactly.
- Prune stopped containers and unused images weekly, and check volume usage before pruning volumes.
Frequently asked questions
What happens to data when a container is removed?
Data written inside the container is deleted with its writable layer. Data stored in a volume survives, because volumes live outside the container. This is why databases and uploaded files always need a volume.
What is the difference between docker stop and docker kill?
The stop command sends SIGTERM first, giving the process ten seconds by default to shut down cleanly, and only then sends SIGKILL. The kill command ends the process immediately, which risks corrupting data in stateful applications.
Why does my container exit immediately?
The usual cause is a main process that exits at once, often because it forked into the background or failed to start. Check the logs with docker logs, which usually show the error, and make sure the start command runs the application in the foreground.
What is the difference between a stopped and a removed container?
A stopped container still exists, with its filesystem and logs available for inspection, and it can be started again. A removed container is deleted entirely, including its writable layer, and only its image remains.
Do restart policies work after a host reboot?
Yes, except for the no policy. The always and unless-stopped policies restart containers when the Docker daemon starts after a reboot, with unless-stopped respecting a container you stopped manually.
How is a container different from an image?
An image is a read-only template built from a Dockerfile. A container is a running instance of an image, with a writable layer on top. Removing a container never removes its image, and one image can run many containers.







