Typorithm · medium

Lifecycle & Cleanup

container-lifecycledevopslifecyclepruneinspect
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Lifecycle & Cleanup

0%

Containers

Containers move through created → running → stopped → removed. docker stop sends SIGTERM then SIGKILL, docker rm deletes a stopped container, docker inspect shows full config and IP, and prune reclaims dangling images. Containers are ephemeral, so persist state in volumes.

A container's lifecycle is created → running → stopped → removed. docker stop web triggers a graceful shutdown: it sends SIGTERM, waits a grace period, then sends SIGKILL if the process has not exited.

docker rm web deletes a stopped container, releasing its name and writable layer. docker inspect web dumps the full JSON config — image, mounts, environment, and the assigned IP address.

docker image prune -a reclaims disk by removing unused images (volume pruning is separate). Because containers are ephemeral, keep important state in volumes and add restart policies so containers come back after crashes or reboots.

01

Lifecycle: created → running → stopped → removed.

02

stop = SIGTERM then SIGKILL; rm deletes a stopped container.

03

inspect shows config and IP; prune reclaims disk.

docker stop web
docker rm web
docker image prune -a
docker inspect web

Read the implementation

Connect each part of the code to the concept before you type.

1. Stop a container

docker stop sends SIGTERM, then SIGKILL after a grace period, halting the container.

docker stop web

2. Remove a container

docker rm deletes a stopped container, freeing its name and writable layer.

docker rm web

3. Reclaim space

docker image prune -a removes unused images to reclaim disk space.

docker image prune -a

4. Inspect config

docker inspect prints the full JSON config, including the container's IP address.

docker inspect web

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Lifecycle & Cleanup: Lesson & Practice · Typorithm | ApplyDjinn