Persistent storage with Dokku
Applications hosted using Dokku run in docker containers and hence all the data is lost everytime the application is re-deployed. For permanent storage we need to either use a database or mount a volume as described below
# Create a Storage volume in /var/lib/dokku/data/storage/fallinprices
dokku storage:ensure-directory fallinprices
# Next we need to tell dokku to mount this directory to the a folder on the container
dokku storage:mount fallinprices /var/lib/dokku/data/storage/fallinprices:/app/storage
# The folder will be available in the container on /app/storage
# Copy your database sqlite files to this folder. I had to scp them in my case
# restart to take effect
dokku ps:restart fallinprices
How to use files
In your code the direction will be present at /app/storage/ .
Personally I set an environment variable like dokku config:set fallinprices DB_DIR=/app/storage/
. In PHP directory path is accessible @ $_ENV['DB_DIR']
In your local environment a different environment variable can be set
Permission issues
If files are created outside the container, then you might have permission issues.
Here a test file was created in /var/lib/dokku/data/storage/fallinprices
directory. This file won’t be writable in the container. Notice its owner is root and not ‘herokuish’
Solution is east ! Simply copy the file in the container and then delete the original file outside the container ! Of course you will have to rename the copied file..