How to properly configure persistent volumes on dokku with rails?

June 2, 2015 2.8k views
Dokku Docker Ruby on Rails Deployment

How to properly configure persistent volumes on dokku/rails?

I have apps running nicely with dokku and ruby on rails. But in every deployment my uploaded files are deleted.

What is the best way to configure the correct path ("public/images" folder of rails) that I don't want destroy after deploy?

I'm running (without success so far):

dokku docker-options:add app_name run "-v /home/uploads/app_name:/home/dokku/app_name/public/images"
dokku docker-options:add app_name deploy "-v /home/uploads/app_name:/home/dokku/app_name/public/images"
2 Answers

I've found the solution.

Just replace the path with /home/uploads/app_name:/app/public/images
or any other location like /var/www/app_name/public/images:/app/public/images

On the left side (/var/www/app_name/public/images) is the path where dokku will save files on the system.

On the right (/app/public/images) indicates which folder (inside rails app) will be saved from.

  • Just to add to this, don't add this option to the build phase (at least in Dokku 0.3.22) it will fail with rm: cannot remove ‘/app/public/images’: Device or resource busy error while pushing or rebuilding, and won't launch the app.

    Handy functions to check that it's correctly set up are:

    • sudo docker ps
    • sudo docker inspect (app_image_NAME)

    The bottom of the json object will have the following values:

    "Volumes": {
        "/app/public/images/projects/images": "/home/dokku/uploads/katz"
    "VolumesRW": {
        "/app/public/images/projects/images": true

Note that as of Dokku 0.5.0, we now have a persistent storage plugin built-in.

Have another answer? Share your knowledge.