DEV Community

How to persist data in docker container

Jibin Liu on September 15, 2018

TL;DR Containers are supposed to be light-weighted. Adding unnecessary data will make it heavy to create and run. Docker provides several ways t...
Collapse
 
prvnbist profile image
Praveen Bisht

Hi, thanks for your article

Can we store multiple containers data in one volume.

Container1
-- Folder
   -- File1.json
   -- File2.json

Container2
-- Folder
   -- File1.json
   -- File2.json

This is what we currently have, it's essentailly that files gets written in each containers by the end user of the app, and there is this one container with our backend that has to scan all the files and show them in file manager as nested structure. So we want to make these containers independent of user generated data and scanning the shared volume would be much more easier for us.

Can we do it like this

Shared Volume
-- Container1Data
   -- Folder
      -- File1.json
      -- File2.json
-- Container2Data
   -- Folder
      -- File1.json
      -- File2.json
Collapse
 
kozelm007 profile image
kozelm007

Hi Liu. Thanks for your explanation, helped me lot as I'm pretty new in Docker. Just wondering if the volume is persistent in case of switching computer off/on?

Collapse
 
jibinliu profile image
Jibin Liu

Hello,

Yes, the data is persisted until you explicitly delete the explicitly-created volume.

Collapse
 
waynemystir profile image
Wayne Small

I get no response when I run any one these docker run ... commands. What I am missing please?

Collapse
 
plggs profile image
Blake Boris