Error connecting n8n to Redis using Docker Compose

Hello everyone,

I am trying to set up n8n with Redis using docker-compose, but I am encountering some issues with the Redis connection. I have checked that Redis is running inside the container and I am able to connect to Redis from within the n8n container. I also have access to Redis from the local server. However, when I try to run n8n, it is unable to connect to Redis and the following error is displayed in the logs:


Server path not specified, so defaulting to ipc.config.socketRoot + ipc.config.appspace + ipc.config.id /tmp/app.bot
starting server on  /tmp/app.bot 
starting TLS server false
starting server as Unix || Windows Socket
ipc bot server started
Initializing n8n process
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
n8n ready on 0.0.0.0, port 5678
Version: 0.221.2
Redis unavailable - trying to reconnect...
 ================================
   Start Active Workflows:
 ================================
   - EDU_PAY (ID: 1)
     => Started
   - Calendar_Proteco_Event (ID: 2)
     => Started

Editor is now accessible via:
https://n8n.com:5678/***** not real :)
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Unable to connect to Redis after 10000. Exiting process

My compose file:

version: "3"

services:
  traefik:
    image: "traefik"
    restart: always
    command:
      - "--api=true"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.web.http.redirections.entryPoint.to=websecure"
      - "--entrypoints.web.http.redirections.entrypoint.scheme=https"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.mytlschallenge.acme.tlschallenge=true"
      - "--certificatesresolvers.mytlschallenge.acme.email=${SSL_EMAIL}"
      - "--certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ${DATA_FOLDER}/letsencrypt:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - n8n_network

  n8n:
    image: n8nio/n8n:latest
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    labels:
      - traefik.enable=true
      - traefik.http.routers.n8n.rule=Host(`${SUBDOMAIN}.${DOMAIN_NAME}`)
      - traefik.http.routers.n8n.tls=true
      - traefik.http.routers.n8n.entrypoints=web,websecure
      - traefik.http.routers.n8n.tls.certresolver=mytlschallenge
      - traefik.http.middlewares.n8n.headers.SSLRedirect=true
      - traefik.http.middlewares.n8n.headers.STSSeconds=315360000
      - traefik.http.middlewares.n8n.headers.browserXSSFilter=true
      - traefik.http.middlewares.n8n.headers.contentTypeNosniff=true
      - traefik.http.middlewares.n8n.headers.forceSTSHeader=true
      - traefik.http.middlewares.n8n.headers.SSLHost=${DOMAIN_NAME}
      - traefik.http.middlewares.n8n.headers.STSIncludeSubdomains=true
      - traefik.http.middlewares.n8n.headers.STSPreload=true
      - traefik.http.routers.n8n.middlewares=n8n@docker
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=my_n8n_user
      - N8N_BASIC_AUTH_PASSWORD=my_n8n_password
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - EXECUTIONS_MODE=queue
      - QUEUE_BULL=true
      - REDIS_URL=redis://redis:6379
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=my_postgres_db
      - DB_POSTGRESDB_USER=my_postgres_user
      - DB_POSTGRESDB_PASSWORD=my_postgres_password
    volumes:
      - ${DATA_FOLDER}/.n8n:/home/node/.n8n
      - /local-files:/files
    networks:
      - n8n_network

  redis:
    image: redis
    ports:
      - "6379:6379"
    networks:
      - n8n_network

  postgres:
    image: postgres
    environment:
      - POSTGRES_DB=my_postgres_db
      - POSTGRES_USER=my_postgres_user
      - POSTGRES_PASSWORD=my_postgres_password
    volumes:
      - ${DATA_FOLDER}/postgres-data:/var/lib/postgresql/data
    networks:
      - n8n_network

networks:
  n8n_network:
    driver: bridge

Looks like the wrong environment vars Environment variables reference | n8n Docs
You’ll want:

QUEUE_BULL_REDIS_HOST=redis

The other defaults should be fine

1 Like
  • Doesn’t work, I tried it:
    QUEUE_BULL_REDIS_URL=redis
    QUEUE_BULL_REDIS_HOST=redis
    QUEUE_BULL_REDIS_URL=redis://redis:6379
    QUEUE_BULL_REDIS_HOST=redis://redis:6379
Last session crashed
♥
Server path not specified, so defaulting to ipc.config.socketRoot + ipc.config.appspace + ipc.config.id /tmp/app.bot
starting server on  /tmp/app.bot 
starting TLS server false
starting server as Unix || Windows Socket
ipc bot server started
Initializing n8n process
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
n8n ready on 0.0.0.0, port 5678
Version: 0.221.2
Redis unavailable - trying to reconnect...
 ================================
   Start Active Workflows:
 ================================
   - EDU_PAY (ID: 1)
     => Started
   - Calendar_Proteco_Event (ID: 2)
     => Started

Editor is now accessible via:


Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Redis unavailable - trying to reconnect...
Unable to connect to Redis after 10000. Exiting process.

log from redis server

1:C 15 Apr 2023 08:29:40.535 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 15 Apr 2023 08:29:40.536 # Redis version=7.0.10, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 15 Apr 2023 08:29:40.536 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 15 Apr 2023 08:29:40.536 * monotonic clock: POSIX clock_gettime
1:M 15 Apr 2023 08:29:40.545 * Running mode=standalone, port=6379.
1:M 15 Apr 2023 08:29:40.545 # Server initialized
1:M 15 Apr 2023 08:29:40.545 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:M 15 Apr 2023 08:29:40.547 * Loading RDB produced by version 7.0.10
1:M 15 Apr 2023 08:29:40.548 * RDB age 10 seconds
1:M 15 Apr 2023 08:29:40.548 * RDB memory usage when created 0.82 Mb
1:M 15 Apr 2023 08:29:40.548 * Done loading RDB, keys loaded: 4, keys expired: 0.
1:M 15 Apr 2023 08:29:40.548 * DB loaded from disk: 0.001 seconds
1:M 15 Apr 2023 08:29:40.548 * Ready to accept connections
root@jzcqjtvqdi:~# redis-cli ping
PONG
root@jzcqjtvqdi:~# 

But if I do - QUEUEUE_BULL_REDIS_HOST=redis
then the server starts without errors, in standard mode, but the web page does not open

So it does work with just the single flag? So there sounds like there is some other issue. I’d suggest starting up with debug logging then N8N_LOG_LEVEL=debug, then if you’re feeling adventurous DEBUG=*.

Looks like you didn’t fill out the help template, so no much more I can offer.

I changed the docker-compose file:

compose
version: "3.8"
services:
  n8n-master:
    image: n8nio/n8n:latest
    depends_on:
      - redis
      - db
    ports:
      - 5678:5678
    environment:
      - DB_POSTGRESDB_DATABASE=postgres
      - DB_POSTGRESDB_USER=postgres
      - DB_POSTGRESDB_PASSWORD=pass
      - DB_POSTGRESDB_HOST=db
      - DB_POSTGRESDB_PORT=5432
      - DB_TYPE=postgresdb
      - N8N_BASIC_AUTH_PASSWORD=123
      - N8N_BASIC_AUTH_USER=admin
      - EXECUTIONS_MODE=queue
      - EXECUTIONS_DATA_MAX_AGE=72
      - EXECUTIONS_DATA_PRUNE="true"
      - GENERIC_TIMEZONE=America/Sao_Paulo
      - N8N_BASIC_AUTH_ACTIVE="true"
      - N8N_ENCRYPTION_KEY=ae1e030c-2bb1-4175-9028-20c2d87276c5
      - QUEUE_BULL_REDIS_HOST=redis
      - QUEUE_BULL_REDIS_PORT=6379
      - N8N_DISABLE_PRODUCTION_MAIN_PROCESS=true
      - N8N_SKIP_WEBHOOK_DEREGISTRATION_SHUTDOWN=true

  n8n-worker-1:
    image: n8nio/n8n:latest
    depends_on:
      - redis
      - db
      - n8n-master
    environment:
      - N8N_ENCRYPTION_KEY=ae1e030c-2bb1-4175-9028-20c2d87276c5
      - EXECUTIONS_MODE=queue
      - QUEUE_BULL_REDIS_HOST=redis
      - QUEUE_BULL_REDIS_PORT=6379
      - DB_POSTGRESDB_DATABASE=postgres
      - DB_POSTGRESDB_USER=postgres
      - DB_POSTGRESDB_PASSWORD=pass
      - DB_POSTGRESDB_HOST=db
      - DB_POSTGRESDB_PORT=5432
      - DB_TYPE=postgresdb
    command: ["n8n", "worker"]

  n8n-worker-2:
    image: n8nio/n8n:latest
    depends_on:
      - redis
      - db
      - n8n-master
    environment:
      - N8N_ENCRYPTION_KEY=ae1e030c-2bb1-4175-9028-20c2d87276c5
      - EXECUTIONS_MODE=queue
      - QUEUE_BULL_REDIS_HOST=redis
      - QUEUE_BULL_REDIS_PORT=6379
      - DB_POSTGRESDB_DATABASE=postgres
      - DB_POSTGRESDB_USER=postgres
      - DB_POSTGRESDB_PASSWORD=pass
      - DB_POSTGRESDB_HOST=db
      - DB_POSTGRESDB_PORT=5432
      - DB_TYPE=postgresdb
    command: ["n8n", "worker", "--concurrency=5"]

  n8n-webhook-1:
    image: n8nio/n8n:latest
    depends_on:
      - redis
      - db
      - n8n-master
    ports:
      - 5679:5678
    environment:
      - N8N_ENCRYPTION_KEY=ae1e030c-2bb1-4175-9028-20c2d87276c5
      - EXECUTIONS_MODE=queue
      - QUEUE_BULL_REDIS_HOST=redis
      - QUEUE_BULL_REDIS_PORT=6379
      - DB_POSTGRESDB_DATABASE=postgres
      - DB_POSTGRESDB_USER=postgres
      - DB_POSTGRESDB_PASSWORD=pass
      - DB_POSTGRESDB_HOST=db
      - DB_POSTGRESDB_PORT=5432
      - DB_TYPE=postgresdb
    command: ["n8n", "webhook"]

  redis:
    image: redis:latest
    volumes:
      - redis-data:/data

  db:
    image: postgres:latest
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=pass
    volumes:
      - db-data:/var/lib/postgresql/data

volumes:
  redis-data:
  db-data:

the system starts, but postgree gives this error when starting the process, nothing goes into the queue.

2023-04-30 13:01:11.084 UTC [25] LOG:  checkpoint complete: wrote 18 buffers (0.1%); 0 WAL file(s) added, 0 removed, 0 recycled; write=1.709 s, sync=0.002 s, total=1.715 s; sync files=18, longest=0.001 s, average=0.001 s; distance=21 kB, estimate=21 kB
2023-04-30 13:01:25.881 UTC [228] ERROR:  duplicate key value violates unique constraint "workflow_statistics_pkey"
2023-04-30 13:01:25.881 UTC [228] DETAIL:  Key ("workflowId", name)=(2, data_loaded) already exists.
2023-04-30 13:01:25.881 UTC [228] STATEMENT:  INSERT INTO "public"."workflow_statistics"("count", "latestEvent", "name", "workflowId") VALUES ($1, $2, $3, $4)

@roughriver74 it looks like PostgreSQL errors are caused by multiple worker nodes trying to write to specific postgresql tables in parallel. I configured containers to start one after another, and this error does not come anymore:

version: "3.8"
services:
  n8n-master:
    image: n8nio/n8n:latest
    depends_on:
      - redis
      - db
    ports:
      - 5678:5678
    environment:
      - DB_POSTGRESDB_DATABASE=postgres
      - DB_POSTGRESDB_USER=postgres
      - DB_POSTGRESDB_PASSWORD=pass
      - DB_POSTGRESDB_HOST=db
      - DB_POSTGRESDB_PORT=5432
      - DB_TYPE=postgresdb
      - N8N_BASIC_AUTH_PASSWORD=123
      - N8N_BASIC_AUTH_USER=admin
      - EXECUTIONS_MODE=queue
      - EXECUTIONS_DATA_MAX_AGE=72
      - EXECUTIONS_DATA_PRUNE="true"
      - GENERIC_TIMEZONE=America/Sao_Paulo
      - N8N_BASIC_AUTH_ACTIVE="true"
      - N8N_ENCRYPTION_KEY=ae1e030c-2bb1-4175-9028-20c2d87276c5
      - QUEUE_BULL_REDIS_HOST=redis
      - QUEUE_BULL_REDIS_PORT=6379
      - N8N_DISABLE_PRODUCTION_MAIN_PROCESS=true
      - N8N_SKIP_WEBHOOK_DEREGISTRATION_SHUTDOWN=true

  n8n-worker-1:
    image: n8nio/n8n:latest
    depends_on:
      - redis
      - db
      - n8n-master
    environment:
      - N8N_ENCRYPTION_KEY=ae1e030c-2bb1-4175-9028-20c2d87276c5
      - EXECUTIONS_MODE=queue
      - QUEUE_BULL_REDIS_HOST=redis
      - QUEUE_BULL_REDIS_PORT=6379
      - DB_POSTGRESDB_DATABASE=postgres
      - DB_POSTGRESDB_USER=postgres
      - DB_POSTGRESDB_PASSWORD=pass
      - DB_POSTGRESDB_HOST=db
      - DB_POSTGRESDB_PORT=5432
      - DB_TYPE=postgresdb
    command: ["n8n", "worker"]

  n8n-worker-2:
    image: n8nio/n8n:latest
    depends_on:
      - redis
      - db
      - n8n-worker-1
    environment:
      - N8N_ENCRYPTION_KEY=ae1e030c-2bb1-4175-9028-20c2d87276c5
      - EXECUTIONS_MODE=queue
      - QUEUE_BULL_REDIS_HOST=redis
      - QUEUE_BULL_REDIS_PORT=6379
      - DB_POSTGRESDB_DATABASE=postgres
      - DB_POSTGRESDB_USER=postgres
      - DB_POSTGRESDB_PASSWORD=pass
      - DB_POSTGRESDB_HOST=db
      - DB_POSTGRESDB_PORT=5432
      - DB_TYPE=postgresdb
    command: ["n8n", "worker", "--concurrency=5"]

  n8n-webhook-1:
    image: n8nio/n8n:latest
    depends_on:
      - redis
      - db
      - n8n-worker-2
    ports:
      - 5679:5678
    environment:
      - N8N_ENCRYPTION_KEY=ae1e030c-2bb1-4175-9028-20c2d87276c5
      - EXECUTIONS_MODE=queue
      - QUEUE_BULL_REDIS_HOST=redis
      - QUEUE_BULL_REDIS_PORT=6379
      - DB_POSTGRESDB_DATABASE=postgres
      - DB_POSTGRESDB_USER=postgres
      - DB_POSTGRESDB_PASSWORD=pass
      - DB_POSTGRESDB_HOST=db
      - DB_POSTGRESDB_PORT=5432
      - DB_TYPE=postgresdb
    command: ["n8n", "webhook"]

  redis:
    image: redis:latest
    volumes:
      - redis-data:/data

  db:
    image: postgres:latest
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=pass
    volumes:
      - db-data:/var/lib/postgresql/data

volumes:
  redis-data:
  db-data:

this file works. I change image n8n for n8nio/n8n:nightly

version: "3.8"
services:
  n8n-master:
    image: n8nio/n8n:nightly
    depends_on:
      - redis
      - db
    ports:
      - 5678:5678
    environment:
      - DB_POSTGRESDB_DATABASE=postgres
      - DB_POSTGRESDB_USER=postgres
      - DB_POSTGRESDB_PASSWORD=pass
      - DB_POSTGRESDB_HOST=db
      - DB_POSTGRESDB_PORT=5432
      - DB_TYPE=postgresdb
      - N8N_BASIC_AUTH_PASSWORD=123
      - N8N_BASIC_AUTH_USER=admin
      - EXECUTIONS_MODE=queue
      - EXECUTIONS_DATA_MAX_AGE=72
      - EXECUTIONS_DATA_PRUNE="true"
      - GENERIC_TIMEZONE=Europe/Moscow
      - N8N_BASIC_AUTH_ACTIVE="true"
      - N8N_ENCRYPTION_KEY=ae1e030c-2bb1-4175-9028-20c2d87276c5
      - QUEUE_BULL_REDIS_HOST=redis
      - QUEUE_BULL_REDIS_PORT=6379
      - N8N_DISABLE_PRODUCTION_MAIN_PROCESS=true
      - N8N_SKIP_WEBHOOK_DEREGISTRATION_SHUTDOWN=true
      
  n8n-worker-1:
    image: n8nio/n8n
    depends_on:
      - redis
      - db
      - n8n-master
    environment:
      - N8N_ENCRYPTION_KEY=ae1e030c-2bb1-4175-9028-20c2d87276c5
      - EXECUTIONS_MODE=queue
      - QUEUE_BULL_REDIS_HOST=redis
      - QUEUE_BULL_REDIS_PORT=6379
      - DB_POSTGRESDB_DATABASE=postgres
      - DB_POSTGRESDB_USER=postgres
      - DB_POSTGRESDB_PASSWORD=pass
      - DB_POSTGRESDB_HOST=db
      - DB_POSTGRESDB_PORT=5432
      - DB_TYPE=postgresdb
      
    command: ["n8n", "worker"]

  n8n-worker-2:
    image: n8nio/n8n
    depends_on:
      - redis
      - db
      - n8n-worker-1
    environment:
      - N8N_ENCRYPTION_KEY=ae1e030c-2bb1-4175-9028-20c2d87276c5
      - EXECUTIONS_MODE=queue
      - QUEUE_BULL_REDIS_HOST=redis
      - QUEUE_BULL_REDIS_PORT=6379
      - DB_POSTGRESDB_DATABASE=postgres
      - DB_POSTGRESDB_USER=postgres
      - DB_POSTGRESDB_PASSWORD=pass
      - DB_POSTGRESDB_HOST=db
      - DB_POSTGRESDB_PORT=5432
      - DB_TYPE=postgresdb
      
    command: ["n8n", "worker", "--concurrency=5"]

  n8n-webhook-1:
    image: n8nio/n8n
    depends_on:
      - redis
      - db
      - n8n-worker-2
    ports:
      - 5679:5678
    environment:
      - N8N_ENCRYPTION_KEY=ae1e030c-2bb1-4175-9028-20c2d87276c5
      - EXECUTIONS_MODE=queue
      - QUEUE_BULL_REDIS_HOST=redis
      - QUEUE_BULL_REDIS_PORT=6379
      - DB_POSTGRESDB_DATABASE=postgres
      - DB_POSTGRESDB_USER=postgres
      - DB_POSTGRESDB_PASSWORD=pass
      - DB_POSTGRESDB_HOST=db
      - DB_POSTGRESDB_PORT=5432
      - DB_TYPE=postgresdb
      
    command: ["n8n", "webhook"]

  redis:
    image: redis:latest
    volumes:
      - redis-data:/data

  db:
    image: postgres:latest
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=pass
    volumes:
      - db-data:/var/lib/postgresql/data

volumes:
  redis-data:
  db-data:

logs worker

UserSettings were generated and saved to: /home/node/.n8n/config
n8n worker is now ready
 * Version: 0.225.2
 * Concurrency: 10
Start job: 6 (Workflow ID: 2 | Execution: 20)
Start job: 4 (Workflow ID: 3 | Execution: 18)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.