Remove All Stopped And Running Containers At Once
Remove All Stopped Containers
To unstop every container at once, use the following command.
docker rm $(docker ps -aq)
- docker ps -aq: This command lists all Docker container IDs in a quiet mode, which means it only outputs the container IDs without any additional information. Here’s what each part does:
- docker ps: Lists all Docker containers.
- -a or –all: Shows all containers, including stopped ones.
- -q or –quiet: Outputs only container IDs.
- $(…): This is command substitution in Bash. The output of the command inside the parentheses is substituted and executed in the outer command.
- docker rm: This command removes Docker containers.
Remove All running Containers
Add the -f argument to the command above.
docker rm -f $(docker ps -aq)
What Is Docker rm Command ?
“docker rm” is used to remove one or more Docker containers that are running on the Docker host. A Docker container uses up system resources like CPU, memory, and disk space when it is running. To free up such resources, you may choose to uninstall a container after using it for a while.
docker rm [OPTIONS] CONTAINER [CONTAINER…]
- OPTIONS: Various options can be used with the docker rm command to modify its behavior.
- CONTAINER: The name or ID of the Docker container(s) to be removed.