✦ For everyone, free.

Practical knowledge for real and everyday life

Home

Container Lifecycle

Container Lifecycle explains how Docker containers are created, run, and terminated, covering key stages from image to runtime

The container lifecycle describes the sequence of states a container moves through — created, running, paused, stopped, removed — and the commands used to transition between them, governing how a container exists from the moment it is first instantiated until it is permanently deleted.

Creating a Container Without Starting It

A container can be created from an image without immediately starting its main process, useful for preparing a container's configuration before it actually runs.

docker create --name myapp-container myapp:1.0

Starting and Stopping a Container

Once created, a container's main process can be started and later stopped, with the container itself persisting (along with its writable layer) between these transitions.

docker start myapp-container
docker stop myapp-container

Stopping a container does not delete it — it remains present, available to be started again later, retaining whatever state exists in its writable layer.

Pausing and Unpausing a Container

A running container's processes can be temporarily suspended without fully stopping them, useful for briefly freezing a container's activity without losing its running state entirely.

docker pause myapp-container
docker unpause myapp-container

Restarting a Container

A container can be restarted directly, combining a stop and start into a single operation, useful for applying configuration changes that require a fresh process start.

docker restart myapp-container

Removing a Container

Removal permanently deletes the container and its writable layer; this step is distinct from stopping and cannot be undone.

docker rm myapp-container

Why Understanding the Container Lifecycle Matters

A clear understanding of these distinct states and transitions is essential for managing containers correctly — confusing "stopped" with "removed," for instance, could lead to either unexpectedly losing data still present in a stopped container's writable layer, or unexpectedly accumulating stopped containers that were never actually cleaned up.