Container Lifecycle
Containers move through created, running, paused, stopped and removed states, each with its own command.
Syntax
docker start|stop|restart|rm CONTAINERA container has a lifecycle. Knowing the states and the commands that move between them keeps your system tidy.
The core commands
docker create— make a container without starting it.docker start— start a stopped container.docker stop— gracefully stop a running container.docker restart— stop then start again.docker pause/docker unpause— freeze and resume processes.docker rm— delete a stopped container.
Listing containers
docker ps shows running containers; add -a to include stopped ones.
Example
# List running containers, then all containers
docker ps
docker ps -a
# Stop, start and remove a container
docker stop web
docker start web
docker rm -f web # -f force-removes even if running
# Remove all stopped containers
docker container pruneWhen to use it
- An ops engineer stops a container gracefully with docker stop before deploying a new version, giving the app 10 seconds to finish in-flight requests.
- A developer uses docker pause to freeze a container mid-process while taking a checkpoint, then resumes with docker unpause.
- A CI pipeline creates containers with docker create and configures volumes before starting them with docker start, separating creation from execution.
More examples
Move through lifecycle states
Shows each lifecycle transition: create, start, stop, and remove, explicitly rather than using docker run.
# Create but don't start
docker create --name myapp myimage:latest
# Start the created container
docker start myapp
# Stop gracefully (SIGTERM, then SIGKILL after 10s)
docker stop myapp
# Remove stopped container
docker rm myappPause and unpause a container
Freezes all processes in a container using cgroups freezer, then resumes them without losing state.
docker run -d --name worker myapp:latest
docker pause worker
docker ps # STATUS shows "Paused"
docker unpause workerForce-kill and check exit code
Sends SIGKILL to forcefully stop an unresponsive container, then checks the exit code for post-mortem analysis.
# Immediately kill (SIGKILL) without waiting
docker kill myapp
# Inspect why the container exited
docker inspect myapp --format '{{.State.ExitCode}} {{.State.Error}}'
Discussion