docker rm
command removes one or more containers.
$ docker rm [OPTIONS] CONTAINER [CONTAINER...]
Here,
Options;
-force
, -f
→ Force the removal of a running container (uses SIGKILL)--link
, -l
→ Remove the specified link--volumes
, -v
→ Remove anonymous volumes associated with the container$ docker rm myContainer
/cloudyfox
):$ docker rm /cloudyfox
/cloudyfox
$ docker rm --force cloudyfox
cloudyfox
$ docker rm --link /app/cloudyfox
Nore: Here, this command removes the underlying link between /app
and /cloudyfox
containers. It also removes all network communication between the two containers.
# This removes all stopped containers
$ docker container prune
# This removes unused containers as well as other docker resources such as images(unused), networks
$ docker system prune
# Or alternatively you can use the following command to remove containers
$ docker rm $(docker ps --filter status=exited -q)
$ docker rm -V cloudyfox
Note: If a volume is specified with a name, it will not remove. Otherwise, it will remove all volumes associated.
$ docker rm -v vol1
Here, the volume vol1
will be removed, but other volumes associated with the container wil remain intact.