docker volume Removal of Volume

  • 2021-10-25 08:15:08
  • OfStack

prune

To use this command, both 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

名称,简写 说明
--filter 提供过滤值。
--force , -f 不提示确认信息,直接删除。

rm

To use this command, both 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 1 or more volumes. From version 1.25, one option--force,-f--is supported to force the removal of one or more volumes.

Added: docker Remove, Crop, Remove (prune) Unused Mirrors, Containers, Volumes, Networks

Refer to docker prune

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

Prune images

docker image prune removes an image that has no label and is not referenced by the container. This image is called an dangling (wobble) image.

Example 1: docker image prune

redis removed, no label and no reference


#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/docker.github.io 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/docker.github.io latest 32ed84d97e30 6 months ago 1GB

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


docker image prune -a

Skip warning prompt:--force or-f


docker image prune -f

Example 3: Performing filter deletion:

Images created in more than 24 hours


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

See the docker image prune manual for information on filters

Remove container s

When the container is stopped, it is not automatically deleted unless--rm--is specified at docker run. A stopped container writable layer still takes up disk space, so clear it and use the command docker container prune.

Other parameters are similar to docker images prune

Remove Volume

Volumes are used by one or more containers and occupy host space. Volumes are not automatically removed, because automatic removal will destroy data.


docker volume prune

Other parameters are similar to docker images prune

Remove Network

The Docker network does not take up disk space, but they create iptables rules, bridge network services, and route entries. Clear the network that is not used by the container


docker network prune

Other parameters are similar to docker images prune

Remove Everything

The docker system prune command is a shortcut to remove images, containers, and networks.

Volumes are also removable in Docker 17.06.0 and earlier. In Docker 17.06.1 or later, you need to specify the parameter-volumes.

Example (no volume 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 ability to remove volumes): 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


Related articles: