docker rm
Remove one or more stopped containers. Cannot remove running containers unless -f is used.
Syntax
docker rm [OPTIONS] CONTAINER [CONTAINER...]
Examples
Example 1
docker rm my-container
Remove a stopped container.
Example 2
docker rm -f my-container
Force remove a running container.
Example 3
docker rm $(docker ps -aq)
Remove all stopped containers.
Common flags
| Flag | Description |
|---|---|
| -f, --force | Force remove running container |
| -v, --volumes | Remove associated volumes |
Tips & best practices
- •Use --rm with docker run to auto-remove on exit.
- •-v removes anonymous volumes; named volumes need explicit docker volume rm.