5

At the moment I am trying to understand some scenarios concerning data persistence.

The Data Volume Container Pattern sounds great, and there are ways to backup the attached volumes. But what if I have no current backup the DataVolumeContainer gets removed (rather than only stopped)?

From what I understand the volume is physically still present on my host system, but I can't attach it to a new container (since there's no referencing container left).

Is there a possibility to restore that volume (e.g. mount it to a new container) by referencing its volume file or the volume name? (assuming that I named the volume)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Ciprian
  • 139
  • 1
  • 3
  • 12

2 Answers2

4

but I can't attach it to a new container (since there's no referencing container left).
Is there a possibility to restore that volume (e.g. mount it to a new container) by referencing its volume file or the volume name (assuming that I named the volume)?

Yes there is: if you can find your old volume path, you can, as I mentioned in "Docker mount dangling volume", restore its content in a new (and empty) data volume container by replacing its mounting path content with the one found in the old path.

I prefer saving that path whenever I create a new data volume container.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you! So basically when i know which volume I want to attach to a new container I can simply use the path to the volume (on the host system) as the host-dir in '-v :'? Awesome! Thank you so much!! :) – Ciprian Nov 26 '15 at 12:36
  • @Ciprian I was not talking about volumes, but data volume containers, which will store data in /var/lib/docker/volumes/xxx. – VonC Nov 26 '15 at 12:41
  • Yeah but you attached the volume of the old Data Volume Container to a new container by modifying its mounting path, right? – Ciprian Nov 26 '15 at 13:07
  • @Ciprian I keep the mounting path of the new one, but put in it the content of the old one (actually, I remove the new mounting path, and rename the old one with the new mounting path: https://github.com/VonC/b2d/blob/65126dcaf418d8cd2c76d969cf5912ec1b671cdd/updateDataContainerPath#L36-L38) – VonC Nov 26 '15 at 13:09
  • You mean 'replace the old one with the new one', right? Either i don't get it :( – Ciprian Nov 26 '15 at 13:21
  • @Ciprian I mean retrieve the content of the old one, and put it in the new data volume container (I am talking about what is stored in /var/lib/docker/volumes) – VonC Nov 26 '15 at 13:29
  • Ahh okay now I get it! So simple! :p Thank you! I'm sure that I'll use your script! Thank you! :) – Ciprian Nov 26 '15 at 13:35
1

Its not clear from your text if you have removed the volume with the container - then its gone - otherwise and by default you can find "raw" docker volumes here: /var/lib/docker/volumes/. Check the docs for docker rm -v.

Normally you would create a volume by docker run ... -v hostpath:containerpath ... and then you have your data always at hostpath available, no matter if you remove your container or not.

CFrei
  • 3,552
  • 1
  • 15
  • 29
  • Thank you for the answer! :) But my question pointed especially to data persistence when dealing with volumes. I was assuming the 'rm' command to be used without the '-v' flag, should have clarified that, sry! – Ciprian Nov 26 '15 at 12:38