If you remove containers that mount volumes, including the initial dbdata
container, or the subsequent containers db1 and db2, the volumes will not
be deleted. To delete the volume from disk, you must explicitly call
docker rm -v against the last container with a reference to the volume. This
allows you to upgrade, or effectively migrate data volumes between containers.
Does It conflictive?
In my test, I deleted all containers without -v, that’s mean no containers use the volumes.
But when I try ls /var/lib/docker/volumes, there are lots of dir with data.
Yes. “Dangling” volumes, which are the files you see in that directory, persist even after all containers that use them are removed.
Unfortunately there’s no easy way if you’ve orphaned a container, you essentially have to do so manually. Current best practices would be to always remove containers with the -v flag, and potentially keep your data in data containers for easier data management.