docker compose rm command
docker compose rm command is used to remove stopped service containers.
The docker compose rm command does not delete running containers; it is mainly used to clean up stopped or no longer needed containers to free up system resources.
Syntax
docker compose rm [OPTIONS] [SERVICE...]
- SERVICE(Optional): The name of the service container to remove. If no service name is specified, all stopped service containers will be removed.
OPTIONS:
-f, --force: Force remove containers without prompting the user for confirmation.-s, --stop: First stop the running containers, then delete them.-v, --volumes: Also remove volumes associated with the containers.
Example
1. Delete all stopped service containers
docker compose rm
Will list and prompt whether to remove all stopped service containers.
2. Force remove all stopped service containers
docker compose rm -f
Directly remove stopped containers without prompting the user for confirmation.
3. Delete stopped containers of a specific service
docker compose rm web
Only remove the stopped container for the web service.
4. Delete and clean up related volumes
docker compose rm -v
Remove stopped containers and also remove the associated volumes.
other extensions