Docker Community Forums

Share and learn in the Docker community.

Volumes persist problems


(CzBiX) #1

This article has two words:

  • Volumes persist until no containers use them
  • 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.

How I manage(reuse/delete) them?


(Nathan Le Claire) #2

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.

In the future, it’s likely that some sort of volume management tooling such as this : https://github.com/docker/docker/pull/8484 will be built right into Docker itself.