ScanSkill

docker rm

docker rm command removes one or more containers.

Syntax

$ 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

Examples

  • Remove a container:
$ docker rm myContainer
  • Remove a container referenced under the link (eg. /cloudyfox):
$ docker rm /cloudyfox

/cloudyfox
  • Force remove:
$ docker rm --force cloudyfox

cloudyfox
  • Remove link of the default bridge network:
$ 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.

  • Remove all the stopped 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)
  • Remove a container with its volumes
$ docker rm -V cloudyfox

Note: If a volume is specified with a name, it will not remove. Otherwise, it will remove all volumes associated.

  • Remove a container and its selective volumes
$ docker rm -v vol1

Here, the volume vol1 will be removed, but other volumes associated with the container wil remain intact.