what happens when docker volume crashes?

1.2k views Asked by At

Alright, I was reading an article on how docker volume is different than a mount. And also how it is better than a mount. After reading it I understood 2 things

  1. volumes are independent of file system
  2. volumes can be independent of containers

which means even if a container dies, a volume that was responsible for say saving some output files related to that container will still be up and running IF other containers want to access that data. Good so far.

However, that bring me to my real question a volume is after all a docker component and is prone to a crash. What happens when volume crashes? since unlike a mount, data is not persisted in a file storage, how do we recover the data that the dying volume used to carry?

1

There are 1 answers

0
BMitch On BEST ANSWER

Revise your first line, "1. volumes are independent of the docker container's union filesystem". Volumes let you mount any other filesystem from outside of the image layers and container's read-write layer that make up the unionfs. Volumes aren't really a docker component that stores your data, they are a docker reference to map your data from another location into the container's filesystem.

That volume mount can be any directory on the host, it may be a named volume with the local driver which defaults to storing under /var/lib/docker/volumes, or it may be using any of the third party volume drivers that pull data in from external sources. The default local volume driver could also mount the data in from an external source like NFS with the appropriate mount options.

So if your container dies, the state of the volume is written to the source filesystem, and you can mount the same volume in another container to pickup where you left off. If you corrupt your volume, then you'd of course need to repair that first. Always take backups of your volumes in case you ever need to rollback.