Persistent storage for n8n

1.4k views Asked by At

I'm running n8n using a Docker container with a cloud hosting service that uses Jelastic.

I got it up and running just fine, but I can't get persistent storage to work. So when I restart the container, I lose all my workflows and credentials. In my environment topology I have created a volume, similar to what I have on my local machine (which does persist the storage), but that hasn't worked. environment storage

I'm a technical product manager, so semi-capable to a point, but this is proving above my head.

Assistance is greatly appreciated!

1

There are 1 answers

1
Virtuozzo On

If we strictly follow the n8n documentation we can't reproduce the mentioned issue, though there was one thread "Can’t get data to persist after system off/on" in the community on this matter with an n8n founder which ended without finding any root cause.

We will provide here a step-by-step deployment process on the Jelastic Platform using Docker Engine CE.

There are many options available but we will stop on a few of them.

The first option is using the Docker Engine CE only, with and without adding volumes.

  1. Follow the Marketplace tab in the Dashboard, choose Docker Engine CE, and deploy it

  2. Open the web ssh console and deploy the n8n application exactly as mentioned in the official documentation

    docker run -it --rm --name n8n -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8n

In Jelastic, the path ~/.n8n is /root/.n8n, so the two files (config and database.sqlite) are created in the pointed path. They are responsible for saving the data and workflows.

  1. If you want to use the Jelastic volumes feature, you may add the default path /root/.n8n to Local Filesystem as is done here. In this case, this volume is saved during the redeploy and it also appears in favorites for quick access to files.

Another option that may be used after deploying the application is to share the config files with Exporting Data feature. It helps to share the needed files to another node/environment.

  1. Deploy the Docker Engine CE as was mentioned above (step 1).

  2. Change the environment topology and add the Extra Storage node or create a separate environment with an Extra Storage node.

  3. Follow the steps in the appropriate documentation to share e.g. the /data directory to the Docker Engine node /root/.n8n. In this case all the data from /root/.n8n will be in fact present in the /data directory on the Extra Storage node.

  4. Deploy the n8n application

    docker run -it --rm --name n8n -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8n

The mentioned files will be available on the Docker Engine node but in fact they are phisically located on the Extra Storage node in the /data directory. If /root/.n8n directory is unmounted or Docker Engine node accidentally deleted/crashed/etc., all files will be still present on the Extra Storage node.

Please note, that the project should run via the console in the same way as is mentioned in the official documentation (step 2 or step 4 accordingly). The volume -v option (-v ~/.n8n:/home/node/.n8n) is obligatory to use. If the poject is run without '-v' option, all workflows are saved in the docker container and are permanently deleted after session in the console is closed or docker container stopped (option --rm is used by default).

The '--restart always' may be used instead to have the application running after the node/environment restart, e.g.

docker run --restart always --name n8n -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8n

To disable the '--restart always' option, you may use

docker update --restart=no $(docker ps -a -q)

To conclude: you may use the steps above to run the n8n application and it should run without any issues. In case of any, please contact us via your Hosting Provider and we eagerly assist you.