AcademyContainment Breach: The Architect's ShipZone 3: Life Cycle Management

Lesson 1: The Puppet Master (Container Lifecycle)

A container is like a puppet — you pull the strings to start it, pause it, stop it, and remove it. Understanding the lifecycle lets you manage containers like a pro.

The Container Lifecycle

     docker create        docker start        docker stop
 ──────────────────→ ──────────────────→ ──────────────────→
    CREATED              RUNNING              STOPPED
 ←────────────────── ←────────────────── ←──────────────────
                      docker pause         docker start
                     ──────────→
                       PAUSED
                     ←──────────
                      docker unpause

                                            docker rm
                                         ──────────────→
                                            REMOVED

Lifecycle Commands

| Command | Action | Example | |---------|--------|---------| | docker run | Create + Start | docker run -d nginx | | docker create | Create only | docker create nginx | | docker start | Start a stopped container | docker start webserver | | docker stop | Graceful shutdown (SIGTERM) | docker stop webserver | | docker kill | Force stop (SIGKILL) | docker kill webserver | | docker restart | Stop + Start | docker restart webserver | | docker pause | Freeze (suspend) | docker pause webserver | | docker unpause | Unfreeze | docker unpause webserver | | docker rm | Remove a stopped container | docker rm webserver |

Running in the Background: -d

Most production containers run detached (in the background):

docker run -d --name webserver nginx
  • -d — Detached mode (returns control to your terminal).
  • --name webserver — Give it a human-readable name.

Stopping vs. Killing

  • docker stop sends SIGTERM — gives the app 10 seconds to shut down gracefully.
  • docker kill sends SIGKILL — instant termination (use only if stop fails).

Removing Containers

docker rm webserver               # Remove a specific container
docker rm $(docker ps -aq)        # Remove ALL stopped containers
docker container prune            # Clean up stopped containers

Auto-Remove: --rm

For one-off tasks, use --rm to automatically delete the container when it stops:

docker run --rm ubuntu echo "I self-destruct!"
booting...

Mission Objective

Master the container lifecycle:

  1. Launch: Run docker run -d --name webserver nginx in the background.
  2. Stop: Shut it down with docker stop webserver.
  3. Revive: Bring it back with docker start webserver.

Mission Control

Run a container in the background

Expected Command

docker run -d --name webserver nginx

Stop the running container

Start the container again