Adding persistent storage to dokku

by Glenn square thumb Glenn Jones, published on 24/10/16

Dokku deploys your app ephemerally, meaning that for every deployment, the source files of your project are a clean copy. Usually the only objects that persist are the ones you explicitly want to persist, such as databases and.. well, databases mostly (postgres, redis).

However dokku also allows you to persist project directories across deployments (persistant storage). That’s useful when you for example need to keep user uploads, commonly using Carrierwave or Paperclip.

The dokku docs are fairly explicit on how to use persistant storage. The standard command is:

dokku storage:mount app-name /var/lib/dokku/data/storage:/storage

This is fairly limited and especially if you have multiple environments on your server, it’s useful to be a little more specific in where you store your data. I recommend using the “more complex workflow” from the dokku docs, in which you make a directory, ensure access rights and then mount the directory into your app.

# creating storage for app "loremipsum_staging"
mkdir -p  /var/lib/dokku/data/storage/staging/uploads
# ensure rights
chown -R dokku:dokku /var/lib/dokku/data/storage/staging/uploads
# mount it (following command should be one line)
dokku storage:mount loremipsum_staging /var/lib/dokku/data/storage/staging/uploads:/app/public/uploads

A small detail while mounting: the /app/ after the the semicolon should always be there. The space after, is essentially your projectroot. I mistook that /app/ for a directory within my rails project, realised that was not the directory I wished to persist, hence removed it from the path and as a result made the persistent storage unsuccesfull. Keep the /app/..

>> A straightforward og-tags and meta data pattern in rails 4

<< Deploy an elixir phoenix application to the smallest digitalocean droplet using dokku

Back to glennjon.es

comments powered by Disqus