Container Lifecycle: Stop and Remove
Last lesson we ran a container in the background and read its output. This time we focus on one idea: how to shut a container down cleanly and then clean it up. We learn docker stop (which sends SIGTERM first — a polite 'please finish' signal, from the primer — waits a grace period, and only then SI
Stop and remove are like switching a device off and then throwing it out: docker stop asks the device to finish nicely before it powers down, but it is still sitting on the shelf switched off — only docker rm actually takes it off the shelf and frees the space.
- SIGTERM
- A polite 'please terminate' signal sent to the container's main process on docker stop, giving it time to close connections and save state before shutting down. (A signal is a short message the OS sends a process — from the primer.)
- SIGKILL
- A signal that drops a process immediately with no chance to refuse. docker stop sends it only if the process has not exited on its own by the end of the grace period after SIGTERM.
- Exited state
- A container whose process has finished. It is no longer running but still exists: docker ps -a still lists it with its exit code, until docker rm deletes it.