To remove existing named or anonymous volumes using the docker volume rm command, they cannot be used in any container (even stopped ones). The standard procedure would be as follows:
For anonymous volumes, if you use the --rm flag for the docker run command, the container will be removed on exit, along with its anonymous volumes. This flag should be used depending on the scenario – in most cases, it is useful for testing and development purposes to make cleanup easier.
During development, you may occasionally need to perform a full cleanup of all of the volumes on your Docker host, for example, if you need to free disk space. The Docker CLI provides a dedicated command that will remove any volumes that are not used in any container:
docker volume prune
Next, we will take a look at bind mounts and how they differ from volumes.