In this guide, we’ll explore how to manage Docker containers by stopping, pausing, resuming, and removing them. You’ll also learn how Linux signals map to Docker commands, plus best practices for cleaning up containers to reclaim resources.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
1. Linux Signals Refresher
Linux processes respond to signals for control and shutdown. Below is a quick overview:| Signal | Action | Description |
|---|---|---|
| SIGSTOP | Pause | Suspends the process, cannot be caught. |
| SIGCONT | Resume | Continues a paused process. |
| SIGTERM | Graceful shutdown | Allows process cleanup before exit. |
| SIGKILL | Forceful kill | Immediately terminates; cannot be trapped. |
SIGTERM is the preferred way to stop a process because it allows cleanup. SIGKILL should be used only if the process does not terminate gracefully.2. Docker Container Equivalents
Docker uses similar primitives at the container level. The table below shows the mappings:| Action | Linux Signal | Docker Command |
|---|---|---|
| Pause | SIGSTOP/SIGCONT | docker pause / docker unpause |
| Stop | SIGTERM → SIGKILL | docker stop |
| Kill | SIGKILL | docker kill --signal=SIGKILL |
| Remove | — | docker rm |
2.1 Running an HTTPD Container
2.2 Pause and Resume
2.3 Stop (SIGTERM then SIGKILL)
SIGTERM, waits the default 10 seconds, then sends SIGKILL if the container is still running.
3. Sending Custom Signals
You can target any signal to a container’s main process:4. Removing a Container
Containers must be stopped before removal:5. Batch Stopping and Removing
When managing multiple containers, leveragedocker ps -q and docker ps -aq:
6. Pruning Stopped Containers
To delete all stopped containers and free disk space:docker container prune permanently deletes all stopped containers. There is no undoing this action.7. Automatic Cleanup with —rm
For ephemeral containers, use--rm to remove them automatically after exit: