docker compose rm command
The docker compose rm command removes stopped service containers.
The docker compose rm command does not remove running containers; it is mainly used to clean up stopped or no-longer-needed containers to free 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: Forces container removal without prompting for confirmation.-s, --stop: First stops running containers, then removes them.-v, --volumes: Also removes volumes associated with the container.
Example
1. Remove all stopped service containers
docker compose rm
Lists all stopped service containers and prompts whether to remove them.
** 2. Force-remove all stopped service containers**
docker compose rm -f
Directly removes stopped containers without prompting for confirmation.
** 3. Remove stopped containers of a specific service**
docker compose rm web
Only removes stopped containers of the web service.
4. Remove and clean up related volumes
docker compose rm -v
Removes stopped containers and also deletes their associated volumes.
Docker Command Reference