Docker volume deletion operation

Docker volume deletion 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 not used by any container.

OPTIONS

Name, abbreviation illustrate
--filter Provide a filter value.
--force , -f Delete without prompting for confirmation.

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

Deletes one or more volumes. Starting from version 1.25, an option --force, -f is supported to force the deletion of one or more volumes.

Supplement: Docker removes, trims, and deletes (prunes) unused images, containers, volumes, and networks

See docker prune

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

Prune images

Docker image prune removes images that are not tagged and are not referenced by containers. These images are called dangling images.

Example 1: docker image prune

Deleted redis, 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/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 images that are not used by containers -a

docker image prune -a

Skip warning prompts: --force or -f

docker image prune -f

Example 3: Execute filter deletion:

Images created more than 24 hours ago

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

For more information about filters, see the docker image prune manual.

Remove containers

When the container is stopped, it is not automatically deleted unless --rm is specified during docker run. A stopped container’s writable layer will still take up disk space, so to clear it, use the docker container prune command.

Other parameters are similar to docker images prune

Removing a Volume

Volumes are used by one or more containers and take up space on the host machine. The volume will not be removed automatically because doing so would destroy the data.

docker volume prune

Other parameters are similar to docker images prune

Remove a network

Docker networks do not take up disk space, but they create iptables rules, bridge network services, and routing entries. Clear the network not used by the container, 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, you need to specify the --volumes parameter.

Example (without removing the volume):

# 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

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • Introduction to container data volumes in Docker
  • Two ways to manage volumes in Docker
  • Docker volumes file mapping method
  • How to implement Docker volume mounting
  • Docker Data Storage Volumes Detailed Explanation
  • Docker volume usage details and examples
  • Docker writes data to the data volume

<<:  Example code for implementing multiple line omissions using three methods of advanced CSS

>>:  The popularity of Chinese domain names in China has ushered in a new round of climax

Recommend

Detailed explanation of CSS background and border tag examples

1. CSS background tag 1. Set the background color...

MySql implements page query function

First of all, we need to make it clear why we use...

How to write memory-efficient applications with Node.js

Table of contents Preface Problem: Large file cop...

Vertical and horizontal splitting of MySQL tables

Vertical Split Vertical splitting refers to the s...

Javascript uses the integrity attribute for security verification

Table of contents 1. Import files using script ta...

How to display percentage and the first few percent in MySQL

Table of contents Require Implementation Code dat...

TortoiseSvn Little Turtle Installation Latest Detailed Graphics Tutorial

There were always problems when installing tortoi...

Vue routing lazy loading details

Table of contents 1. What is lazy loading of rout...

Detailed explanation of Vue's SSR server-side rendering example

Why use Server-Side Rendering (SSR) Better SEO, s...

How to set the memory size of Docker tomcat

When installing Tomcat in Docker, Tomcat may over...

Optimizing the slow query of MySQL aggregate statistics data

Written in front When we operate the database in ...

Use of Vue3 table component

Table of contents 1. Ant Design Vue 1. Official w...

Vue implements graphic verification code login

This article example shares the specific code of ...