Removing a volume
The same as with creating volumes, there are two ways of removing a volume in Docker. Firstly, you can remove a volume by referencing a container's name and executing the docker rm -v
command:
$ docker rm -v <containerName or ID>
Docker will not warn you, when removing a container without providing the -v
option, to delete its volumes. As a result, you will have dangling
volumes—volumes that are no longer referenced by a container. As you remember, they are easy to get rid of using the docker volume prune command.
Another option to remove the volume is by using the docker volume rm
command:
$ docker volume rm <volumeName or ID>
If the volume happens to be in use by the container, Docker Engine will not allow you to delete it and will give you a warning message:

As you can see, creating, sharing, and removing volumes in Docker is not that tricky. It's very flexible and allows the creating a setup you will need for your applications. But there's more to this flexibility...