I was trying to pass credentials data from the .env file to the n8n server. I am using Docker Compose. Here is my YAML file :
services:
n8n:
image: n8nio/n8n:latest
restart: always
ports:
- "5678:5678"
env_file:
- .env
# environment:
# - FIREBASE_SERVICE_ACCOUNT_EMAIL=${FIREBASE_SERVICE_ACCOUNT_EMAIL}
# - FIREBASE_REGION=${FIREBASE_REGION}
# - FIREBASE_PRIVATE_KEY=${FIREBASE_PRIVATE_KEY}
# - OPENAI_API_KEY=${OPENAI_API_KEY}
volumes:
- n8n_data:/home/node/.n8n
- ./local-files:/files
volumes:
n8n_data:
And here is my .env file:
N8N_BLOCK_ENV_ACCESS_IN_NODE=false
N8N_BLOCK_FILE_ACCESS_TO_N8N_FILES=false
N8N_PORT=5678
N8N_HOST=localhost
N8N_PROTOCOL=http
WEBHOOK_URL=http://localhost:5678/
GENERIC_TIMEZONE=Asia/Tokyo
TZ=Asia/Tokyo
NODE_ENV=production
N8N_ENCRYPTION_KEY=testkey
# Firebase
[email protected]
FIREBASE_REGION=asia-northeast1
FIREBASE_PRIVATE_KEY=-----BEGIN PRIVATE KEY-----\nXXX==\n-----END PRIVATE KEY-----\n
# OpenAI
OPENAI_API_KEY=sk-xxxxx
N8N_ALLOW_ENV_VARIABLES=true
N8N_ALLOW_ENV_VARIABLES=true is already there. I can see the variables are loaded when I enter Printenv in the console of the Docker volume.
However, either “$env” or “process.env” always returns an error or is empty, no matter whether from a code node or from the expression field.
I’ve been stuck for a few days. I’ve tried to ask different LLMs, find info from docs, and search for questions from others. I still don’t get it
Information on your n8n setup
- n8n version: latest
- Database (default: SQLite): firebase
- n8n EXECUTIONS_PROCESS setting (default: own, main): default
- Running n8n via (Docker, npm, n8n cloud, desktop app): docker compose
- Operating system: WLS on Windows
