Can't get data to persist after system off/on

I’ve been using n8n for the last few days with Docker to try and get the hang of how it works but the config file is generated each time I start n8n so I lose all my data. I’m starting it by following the instruction in the Quick Start section of the documentation.

docker run -it --rm \ --name n8n \ -p 5678:5678 \ -v ~/.n8n:/root/.n8n \ n8nio/n8n

The config file is apparently created at home > node > .n8n but when I try to access that path I’m told it doesn’t exist. Any restart of the computer means I lose my data. I manually created the directory yesterday, started n8n again and was able to restart my system and keep my data, even though the config file didn’t appear to be being saved there. Now this morning after turning on my computer and starting n8n the config file was created again and I’m starting from scratch again. I’m sure this is a simple issue but I can’t work out what I’m doing wrong.

So, I have a couple of questions:

  1. What am I doing wrong?
  2. Where is the config file and how do I access it?

There are a couple of ways to do this but the easiest is to commit your changes to the docker image.

Thanks a lot @Tephlon but that should in this case not be needed. It already looks correct.

@33mesg To be honest I am not sure what is going wrong. The command you are using will by default persist the data as it mounts your local .n8n folder in “docker” with the -v ~/.n8n:/root/.n8n part of the command.

It is /root and not /home/node to keep it backward compatible with the original behavior. Internally it creates a symlink: https://github.com/n8n-io/n8n/blob/master/docker/images/n8n/docker-entrypoint.sh and that is why it should work fine.

Not sure if it causes for some reason problems for you but you can try to directly mount it to the “correct” folder like this:

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

If also that does not work, It is possible that there are maybe some file access issues or something else. Did the .n8n folder really got created correctly in your home folder?

@Tephlon @jan Thank you for the replies.

Now I’m really confused. After a fresh boot I started n8n as I did before and there was no message about creating the config file like there was earlier. It started fine but I only had access to the two empty workflows I made earlier today to test whether I was able to keep them after a reboot.

Now I’ve just rebooted my computer and done the exact same thing again, and again no message about creating the config file. This time however, I have access to my workflows from yesterday as well as the empty test workflows from this morning. Yesterday’s workflows being lost this morning is the whole reason I posted here. I really don’t understand what’s happening.

The /home/node part is definitely the message I’m shown when it says about creating the config file. Is that not normal? I’m running Ubuntu 18.04 if that could be a factor in anything. I thought it looked odd but I’m very new to all of this so I assume it’s another thing I don’t understand yet. I manually created the .n8n folder too. I’m sure it was a coincidence that it started working after I did that as the folder doesn’t appear to be used at all.

Apologies for a further basic question, but how would I go about backing up the database? I assume it’ll be SQLite as I haven’t changed any database settings. As I’ve been able to regain access to my workflows from yesterday I don’t think I I’m in much danger of losing them completely but It’d be good for peace of mind going forward to be able to back it up.

Also, to have n8n start on boot would I just need to add --restart always to the run command?

Sounds very strange. Have currently sadly no idea what is happening there.

n8n has nothing for backup built-in, so what you would have to do is to simply copy the database.sqlite file which can be found in the ~/.n8n folder. Apart from that can you also press “Download” in the “Workflow” menu. It will then download the currently open workflow as JSON.

Yes I think if you have the --restart in the docker command it should normally make sure that n8n keeps running. But not 100% sure if it does then also make sure that it restart again after rebooting.

Thank you, I’ve got the backups sorted. Everything appears to be working as intended now after multiple boots so whatever gremlins there were seem to have been flushed out. If it happens again I’ll see if I can work out why and report back.

And --restart always is working as I’d hoped. n8n now starts on boot and continues any active workflows.

Great to hear that everything is working fine! Lets hope they do not come back!

Then have fun with n8n!