Docker rm Command
The docker rm command is used to delete one or more stopped containers.
The docker rm command does not delete running containers; if you need to stop a container first, you can use the docker stop command.
Syntax
docker rm [OPTIONS] CONTAINER [CONTAINER...]
CONTAINER [CONTAINER...]: The name or ID of one or more containers to delete.
OPTIONS description:
-f,--force: Force deletion of a running container (useSIGKILLsignal).-l,--link: Delete the specified link instead of the container itself.-v,--volumes: Delete volumes mounted by the container.
Delete a single container:
docker rm
You can delete multiple containers at once by separating their IDs or names with spaces:
docker rm ...
You can use the following command to delete all stopped containers:
docker container prune
This command prompts you to confirm deletion of all stopped containers.
Example
Suppose you have the following two containers:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
abcd1234 nginx "nginx -g 'daemon…" 2 minutes ago Exited (0) 1 minute ago my_nginx
efgh5678 redis "redis-server" 3 minutes ago Exited (0) 2 minutes ago my_redis
You can use the following command to delete them:
docker rm abcd1234 efgh5678
Alternatively, you can delete them by container name:
docker rm my_nginx my_redis
Delete all stopped containers:
docker rm $(docker ps -a -q)
For more information, see:Docker cleanup commands
Docker Command Reference