Hi @mmac, I am sorry you are having trouble.
N8N_ENCRYPTION_KEY=fioengo8585h
and it didn’t work, I couldn’t access N8N from the web, it said bad gateway.
First things first, I don’t think the N8N_ENCRYPTION_KEY
is related to a possible bad gateway error. If your encryption key is wrong, n8n would instead be unable to read existing credentials (or identify itself against the enterprise license server).
That didn’t work, so I did this, which I found here in the forum:
N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
When I start it with docker compose up -d, it said “WARN[0000] The “N8N_ENCRYPTION_KEY” variable is not set. Defaulting to a blank string.”
This tells docker to use interpolation rather than a hard coded environment variable. I would suggest avoiding this, at least when getting started and instead provide the actual values directly in your docker compose file.
Now, with that out of the way, the bad gateway error would instead typically be thrown by a load balancer or reverse proxy. Is this docker compose setup the only application running on your server? Or is there a chance you already have an application like caddy or nginx running on your server? In this case you won’t need traefik from your docker compose file.
Then I started Redis per the docs with:
docker run --name some-redis -p 6379:6379 -d redisThen I went back in to docker-compose.yml and added:
QUEUE_BULL_REDIS_HOST=localhost
QUEUE_BULL_REDIS_PORT=6379localhost didn’t work, so I tried:
QUEUE_BULL_REDIS_HOST=some-redis and
QUEUE_BULL_REDIS_HOST=redis
This will fail because your docker compose setup lives on a separate docker network than your redis instance started outside of your docker compose file. You probably want to add redis to your docker compose file instead so all containers share the same network.
An example docker-compose.yml
file starting n8n in queue mode with all required services (n8n main, instance, n8n worker instance, Redis, and a Postgres database) could look like so:
services:
postgres:
image: postgres:15
restart: unless-stopped
environment:
- POSTGRES_USER=n8n
- POSTGRES_PASSWORD=n8n
- POSTGRES_DB=n8n
volumes:
- ./db_data:/var/lib/postgresql/data
ports:
- 5432:5432
healthcheck:
test: ['CMD-SHELL', 'pg_isready -h localhost -U n8n -d n8n']
interval: 5s
timeout: 5s
retries: 10
redis:
image: redis:6-alpine
restart: unless-stopped
healthcheck:
test: ['CMD', 'redis-cli', 'ping']
interval: 5s
timeout: 5s
retries: 10
n8n_main:
image: n8nio/n8n:1.21.1
restart: unless-stopped
environment:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_USER=n8n
- DB_POSTGRESDB_PASSWORD=n8n
- QUEUE_BULL_REDIS_HOST=redis
- N8N_ENCRYPTION_KEY=foobarbaz
- EXECUTIONS_MODE=queue
ports:
- 5678:5678
volumes:
- ./n8n_data:/home/node/.n8n
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
n8n_worker:
image: n8nio/n8n:1.21.1
restart: unless-stopped
environment:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_USER=n8n
- DB_POSTGRESDB_PASSWORD=n8n
- QUEUE_BULL_REDIS_HOST=redis
- N8N_ENCRYPTION_KEY=foobarbaz
- EXECUTIONS_MODE=queue
command: worker
volumes:
- ./n8n_data:/home/node/.n8n
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
n8n_main:
condition: service_started
No additional containers and no .env file are needed in this case, just two empty folder n8n_data
and db_data
in the same directory.
You can then start n8n using docker compose up
, after a short wait you should see the “Editor is now accessible via:” message and can open n8n on http://localhost:5678
: