Removing volumes

Volumes can be removed using the docker volume rm command. It is important to remember that removing a volume destroys the containing data irreversibly and thus is to be considered a dangerous command. Docker helps us a bit in this regard as it does not allow us to delete a volume that is still in use by a container. Always make sure before you remove or delete a volume that you either have a backup of its data or you really don't need this data anymore.

The following command deletes our my-data volume that we created earlier:

$ docker volume rm my-data 

After executing the preceding command, double-check that the folder on the host has been deleted.

To remove all running containers to clean up the system, run the following command:

$ docker container rm -f $(docker container ls -aq)