SoFunction
Updated on 2025-03-09

Docker volume delete operation

prune

To use this command, both the client and daemon API versions must be at least 1.25. Use the docker version command on the client to check the client and daemon API versions.

docker volume prune [OPTIONS]

Delete local volumes that are not used by any container.

OPTIONS

Name, abbreviation illustrate
--filter Provides filtered values.
--force , -f Delete the confirmation information without prompting.

rm

To use this command, both the client and daemon API versions must be at least 1.21. Use the docker version command on the client to check the client and daemon API versions.

docker volume rm [OPTIONS] VOLUME [VOLUME...]

Delete one or more volumes. Starting from version 1.25, an option --force , -f is supported to force delete one or more volumes.

Supplement: docker removes, crops, and deletes (prune) unused images, containers, volumes, and networks

refer todocker prune

Provides the prune command to remove unused images, containers, volumes, and networks.

Prune images

docker image prune removes images that have no tags and are not referenced by containers. This image is called a dangling image.

Example 1: docker image prune

Redis removed, no tags and no references

#docker ps -a
CONTAINER ID IMAGE  COMMAND CREATED STATUS PORTS  NAMES
# docker images
REPOSITORY    TAG  IMAGE ID  CREATED  SIZE
nginx     latest ae2feff98a0c 4 days ago  133MB
redis     <none> ef47f3b6dc11 8 days ago  104MB
centos     latest 300e315adb2f 12 days ago 209MB
ubuntu     latest f643c72bc252 3 weeks ago 72.9MB
docs/ latest 32ed84d97e30 6 months ago 1GB
# docker image prune
# docker images
REPOSITORY    TAG  IMAGE ID  CREATED  SIZE
nginx     latest ae2feff98a0c 4 days ago  133MB
centos     latest 300e315adb2f 12 days ago 209MB
ubuntu     latest f643c72bc252 3 weeks ago 72.9MB
docs/ latest 32ed84d97e30 6 months ago 1GB

Example 2: Remove all images that are not used by containers -a

docker image prune -a

Skip warning prompt: --force or -f

docker image prune -f

Example 3: Perform filtering and deletion:

Image created over 24 hours

docker image prune -a --filter "until=24h"

About the filter, viewdocker image prune manual

Remove containers

When the container is stopped, it will not be deleted automatically unless --rm is specified when docker run. A stop-writable container will still take up disk space, so clear it and use the docker container prune command.

Other parameters are similar to docker images prune

Remove volume

The volume is used by one or more containers and takes up host space. Volumes are not automatically removed because they will corrupt data.

docker volume prune

Other parameters are similar to docker images prune

Remove the network

Docker networks do not take up disk space, but they create iptables rules, bridge network services, and route entries. Clear networks that are not used by containers, do this

docker network prune

Other parameters are similar to docker images prune

Remove Everything

The docker system prune command is a shortcut for removing images, containers, and networks.

In Docker 17.06.0 and earlier, volumes can also be removed. In Docker 17.06.1 or later, the parameter --volumes needs to be specified.

Example (the volume was not removed):

# docker system prune
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - all build cache
Are you sure you want to continue? [y/N] y

Example (with the function of removing volume): Add --volumes

# docker system prune --volumes
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all volumes not used by at least one container
  - all dangling images
  - all build cache
Are you sure you want to continue? [y/N] y

Other parameters are similar to docker images prune

The above is personal experience. I hope you can give you a reference and I hope you can support me more. If there are any mistakes or no complete considerations, I would like to give you advice.