Larry
Larry

Reputation: 65

How to convert a non-persistent docker container to persistent storage (volume)?

The problem

I messed up really badly, started a prestashop docker container (via compose) for production and forgot to add a persistent volume to it. I've set up my store and now all my data is dangling. I need to somehow convert my current docker container to one with persistent volume.

Things I've tried

I've copied all data from current container to a local folder, created a new compose file and everything would work if I chmod -R 777 whole directory but people go to hell for these types of crimes, so that's not an option.

As I'm not an expert, I have no other ideas.

Upvotes: 1

Views: 1067

Answers (2)

Larry
Larry

Reputation: 65

Alright,

So it was a pretty simple solution:

  1. sudo su
  2. go to the non-persistent container storage location which you can get by using docker inspect container take the long string hash 822adf62adsomethingsomething.
  3. then cd /var/lib/docker/overlay2/822adf62adsomethingsomething/merged. There you have all your docker container files.
  4. cp -a whateveryouwant /whereeveryouwant as cp -a keeps permissions and owners intact.
  5. profit

Upvotes: 1

jordanvrtanoski
jordanvrtanoski

Reputation: 5557

The issue you have is most probably related to the user id / group id that is owning the files from the old container. When you move to the new container, if the IDs are not same you will have problem, so chmod -R 777 is fixing this problem, but the gates of hell are wide open.

It's better to understand which user id and group id should be the owners of the files and use chown and chgrp to set the right owners from the new container.

Upvotes: 1

Related Questions