Describe the problem/error/question
I have a self-hosted n8n instance running for several months on a Synology NAS via Docker Compose. The encryption key was auto-generated at first launch and stored in the /home/node/.n8n/config file.
I want to explicitly set N8N_ENCRYPTION_KEY as an environment variable in my Docker Compose setup, so that I don’t depend solely on the config file. This would make migrations and container recreation safer.
Here’s what I did:
-
Read the
encryptionKeyvalue directly from the config file on the NAS mounted volume:cat /volume1/docker/n8n/config -
Copied that value into a
.envfile next to mydocker-compose.yml:N8N_ENCRYPTION_KEY=value-from-config -
Added the variable to my compose:
environment: N8N_ENCRYPTION_KEY: "${N8N_ENCRYPTION_KEY}" -
Restarted with
docker compose downthendocker compose up -d
After restart, n8n behaved as a fresh install: account creation screen, all workflows and credentials gone.
I immediately removed the N8N_ENCRYPTION_KEY variable from the compose and restarted. n8n picked up the key from the config file again and everything was restored (credentials, workflows, etc.).
What is the error message (if any)?
No error in the logs. n8n simply started as a new instance, ignoring existing data.
Please share your workflow
N/A — this is a configuration issue, not workflow-related.
Share the output returned by the last node
N/A
My questions
Has anyone successfully migrated their encryption key from the auto-generated config file to a Docker Compose environment variable?
If so, what method did you use? Are there known pitfalls (encoding, special characters, .env file format, how n8n behaves when both the environment variable and the config file coexist)?
Any analysis or leads would be appreciated.
Information on your n8n setup
-
n8n version: 2.7.5
-
Database: SQLite
-
n8n EXECUTIONS_PROCESS setting: default
-
Running n8n via: Docker (docker compose on Synology NAS)
-
Operating system: Synology DSM 7.x