Docker Container Lifecycle

Every Docker container goes through a lifecycle of states. Understanding these states and how to transition between them is essential for effective container management. This guide covers all container states: created, running, paused, stopped, and deleted.

Created Running Paused Stopped Deleted
Container Lifecycle Overview

A Docker container progresses through several distinct states during its lifetime. Understanding these states helps you manage containers effectively, debug issues, and optimize resource usage.

CREATED docker create
RUNNING docker start / run
PAUSED docker pause
docker unpause docker start
RUNNING
STOPPED docker stop / kill
docker rm / docker rm -f
DELETED container removed
You can check a container's current state using docker ps -a. The STATUS column shows the state: "Up" for running, "Exited" for stopped, "Paused" for paused, "Created" for created but not started.
State 1: Created

A container enters the Created state when you use docker create or docker container create. In this state, the container's filesystem has been prepared, but no processes are running. The container exists on disk but consumes minimal resources. This is useful when you want to prepare a container to run later, or when you want to inspect its configuration before starting.

You can also create a container implicitly using docker run --name mycontainer nginx—the container goes through the Created state briefly before transitioning to Running. To see containers in the Created state, use docker ps -a and look for STATUS "Created".

# Create a container without starting it docker create --name mynginx nginx # List all containers (including created) docker ps -a # Inspect a created container's configuration docker inspect mynginx # Start a created container docker start mynginx
State 2: Running

The Running state is the primary active state of a container. In this state, the container's main process is executing. The container consumes CPU, memory, and other resources. You can interact with running containers through docker exec, view their logs, and access their network ports.

A container enters the Running state from Created via docker start, or directly from an image via docker run. From Running, a container can transition to Paused (docker pause), Stopped (docker stop or docker kill), or continue running until its main process exits naturally.

# Run a container (creates and starts) docker run -d --name web nginx # Start an existing created container docker start web # List only running containers docker ps # Execute commands inside a running container docker exec web ls -la # View logs from a running container docker logs -f web
A container stops automatically when its main process exits. For example, a container running a script that completes will exit. A web server container runs continuously until explicitly stopped.
State 3: Paused

The Paused state freezes all processes inside a container using cgroups freezer. In this state, the container's processes are suspended and not scheduled by the CPU. The container's memory is preserved, and network connections are held. This is different from Stopped (which terminates processes) and is useful for temporarily suspending workloads without losing state.

Paused containers cannot be interacted with via docker exec, and their logs are frozen. Use docker unpause to resume normal operation. Paused containers still consume memory but not CPU cycles.

# Pause a running container docker pause web # List containers (paused containers show "Up (Paused)") docker ps # Unpause a container docker unpause web # Verify container is running again docker ps
Pausing a container for long periods can cause network timeouts. Use pause sparingly for short-term suspension, not as a replacement for proper stopping.
State 4: Stopped (Exited)

A container enters the Stopped (or Exited) state when its main process completes or is terminated. This can happen naturally (the process finished its work), via docker stop (graceful shutdown with SIGTERM), or via docker kill (immediate SIGKILL). Stopped containers still exist on disk—their filesystem and configuration are preserved, but they consume no CPU or memory.

You can restart a stopped container with docker start, which resumes from the same state (including any data written to the container's filesystem). This is useful for containers that need to run periodically or for debugging after a failure.

# Gracefully stop a container (SIGTERM, then SIGKILL after 10s) docker stop web # Immediately kill a container (SIGKILL) docker kill web # List all containers including stopped docker ps -a # Restart a stopped container docker start web # View exit code of a stopped container docker inspect web --format='{{.State.ExitCode}}'
Use docker inspect to see why a container stopped. The State.ExitCode and State.Error fields provide valuable debugging information.
State 5: Deleted

Deletion is the final state in a container's lifecycle. When you delete a container with docker rm, the container's filesystem and metadata are removed from disk. Deleted containers cannot be recovered. Any data written to the container's writable layer (not in volumes) is permanently lost.

You can only delete containers that are stopped (or use -f to force delete a running container). Use docker container prune to remove all stopped containers at once, which is useful for cleaning up after testing or development.

# Remove a stopped container docker rm web # Force remove a running container (stops it first) docker rm -f web # Remove all stopped containers docker container prune # Remove all containers (running and stopped) docker rm -f $(docker ps -aq) # Clean up everything (containers, images, networks, cache) docker system prune
When you delete a container, any data stored only in the container's writable layer is lost forever. Use Docker volumes for persistent data that should survive container deletion.
State Transition Commands Reference
From StateTo StateCommand
(None)Createddocker create <image>
CreatedRunningdocker start <container>
(None)Runningdocker run <image>
RunningPauseddocker pause <container>
PausedRunningdocker unpause <container>
RunningStoppeddocker stop <container>
RunningStoppeddocker kill <container>
StoppedRunningdocker start <container>
Created/StoppedDeleteddocker rm <container>
RunningDeleteddocker rm -f <container>
Practical Example: Following a Container Through Its Lifecycle
# 1. CREATE a container (Created state) docker create --name test nginx docker ps -a | grep test # CONTAINER ID IMAGE STATUS NAMES # abc123 nginx Created test # 2. START the container (Running state) docker start test docker ps | grep test # abc123 nginx Up 2 seconds test # 3. PAUSE the container (Paused state) docker pause test docker ps | grep test # abc123 nginx Up 2 seconds (Paused) test # 4. UNPAUSE the container (Back to Running) docker unpause test # 5. STOP the container (Stopped/Exited state) docker stop test docker ps -a | grep test # abc123 nginx Exited (0) 2 seconds ago test # 6. START again (Running from Stopped) docker start test # 7. DELETE the container (Deleted state) docker stop test docker rm test docker ps -a | grep test # (no output - container is gone)
Frequently Asked Questions
What's the difference between docker stop and docker kill?
docker stop sends SIGTERM, allowing the container to shut down gracefully (default 10 seconds). docker kill sends SIGKILL, immediately terminating the process. Always try stop first; use kill only for unresponsive containers.
Why is my container stuck in "Created" state?
A container stays in Created state if you used docker create but never started it. Use docker start <container> to run it, or docker rm <container> to remove it.
Can I recover a deleted container?
No. Once a container is deleted with docker rm, its filesystem and metadata are permanently removed. However, if you used volumes for persistent data, that data is still available to new containers.
Why does my container exit immediately after starting?
The container's main process completed quickly. For example, running docker run ubuntu echo hello prints "hello" and exits. Use docker run -it ubuntu bash for interactive sessions, or run a long-running process like a web server.
What's the difference between a paused and a stopped container?
Paused containers freeze processes but preserve memory and network connections (they can be resumed quickly). Stopped containers terminate all processes and release CPU/memory but preserve the filesystem (they take longer to restart).
How do I automatically remove a container after it stops?
Use the --rm flag with docker run: docker run --rm nginx. The container is automatically deleted when it stops, perfect for one-off tasks.
Can I restart a container with different configuration?
No, containers are immutable. To change configuration, create a new container from the same image with the new settings, or use docker commit to create a new image from a modified container (not recommended for production).
How do I see why a container stopped?
Use docker inspect <container> --format='{{json .State}}' to see the exit code and error message. Common exit codes: 0 (success), 1 (general error), 137 (SIGKILL), 143 (SIGTERM).
Previous: Understanding Docker Images Next: Dockerfile Basics

Understanding the container lifecycle gives you complete control over your Docker environments. Master these states and transitions to manage containers with confidence.