All n8n data is lost after docker stop & restart

Describe the problem/error/question

Hello! Totally newbie in n8n, but I would like to use it in some my projects later.
Each time I manually stop and restart n8n via docker, I am loosing all my config. This is n8n Community Edition.
I need to register my account every time and all my workflows and credentials are lost, I have to apply my license key again.
I am using local on-prem n8n installation via docker on Ubuntu 24.04.
My docker-compose.yml file seems to be correct.
When I restart whole Ubuntu machine, the config and all data is persistent after reboot. Data is cleared only when services are manually stopped and started.
Any hints, guys?

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @Robert5

What this sounds like to me is a persistence issue rather than n8n clearing data on its own.
In Docker, n8n stores the default SQLite database file and encryption key under /home/node/.n8n, so if that folder isn’t mounted to a persistent volume, or if the container is being recreated against a different/empty mount when you manually stop and start it, you’ll see exactly this kind of “fresh install” behavior with lost users, workflows, credentials, and license data. I’d first check whether your compose file really mounts /home/node/.n8n persistently, and also whether you’re using docker compose stop/start versus something that recreates the container or points it at a different working directory or volume.

1 Like

You’re probably using docker compose down which removes containers and anonymous volumes. Use docker compose stop and docker compose start instead. Also make sure your docker-compose.yml uses a named volume for /home/node/.n8n, not an anonymous one.

yeah docker compose down wipes the volumes if they’re anonymous — stop/start is the right move. one gotcha we’ve run into: the encryption key can get out of sync between container runs if you’re not setting DB_ENCRYPTION_KEY consistently in your env vars. make sure that’s pinned on restart or you’ll hit decryption errors later.

Hello,

Thanks for all your replies.

I have created directory /home/node within my / filesystem.

My docker-compose.yml configuration looks like this:

services:
n8n:
image: n8nio/n8n
restart: always
ports:
- “5678:5678”
environment:
- GENERIC_TIMEZONE=“Europe/Warsaw”
- TZ=“Europe/Xwarsaw”
- N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
- N8N_RUNNERS_ENABLED=true
- WEBHOOK_URL=“https://my-domain-url”
- N8N_PUSH_BACKEND=websocket

  volumes:
  - n8n_data:/home/node/.n8n

volumes:
n8n_data:

Should be anything (a file, a directory) inside /home/node directory?

What permissions shoud be set for /home/node?

REGARDS

hey @Robert5 — the named volume setup looks correct, you don’t need to create /home/node manually on the host — Docker manages that entirely, permissions included.

two things worth fixing in your compose file though:

  1. there’s a typo in the timezone: Europe/Xwarsaw should be Europe/Warsaw
  2. env var values in docker-compose YAML shouldn’t have quotes around them — so GENERIC_TIMEZONE="Europe/Warsaw" should just be GENERIC_TIMEZONE=Europe/Warsaw. with the quotes, Docker passes them as literal values including the quote characters, which can cause unexpected behavior.

with those fixed, and using docker compose stop / docker compose start instead of down, your data should persist fine.

Hi Ben,

Thanks for your tips.

I clear all typos and quotes in .yml file.

Now I am stopping n8n using ‘docker compone stop’ (not down).

It looks like now all my data persits accross all host restarts and starts/stops.

Thank you again!

Glad it’s all working now! Yeah, quoted env var values in docker-compose is one of those silent gotchas that’s easy to miss. Good luck with your n8n projects!