Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Docker rm Command

Docker rm Command

Docker Command ReferenceDocker Command Reference


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...]

OPTIONS description:

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 ReferenceDocker Command Reference