Docker rm command

Docker command reference


The docker rm command is used to delete one or more containers that have been stopped.

The docker rm command does not delete running containers; if you need to stop the 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 delete running containers (useSIGKILLsignal).
  • -l, --link: Delete the specified link, rather than the container itself.
  • -v, --volumes: Delete the volumes mounted by the container.

Delete a single container:

docker rm <container_id_or_name>

You can delete multiple containers at once by separating the container IDs or names with spaces:

docker rm <container_id_or_name1> <container_id_or_name2> ...

You can use the following command to delete all stopped containers:

docker container prune
This command will prompt you to confirm the 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 using container names:

docker rm my_nginx my_redis

Delete all stopped containers:

docker rm $(docker ps -a -q)

See more content at:Docker cleanup Command


Docker command reference

other extensions