Healthcheck of N8N services

Hi. I am trying to use the healthcheck option on editor to display the status healthy or unhealthy. I am not able to neither access the n8n local instance neither obtain the status healthy when the instance is healthy. What am I doing wrong?

    #healthcheck:
    #  test: ["CMD", "curl", "-f", "http://localhost:5678/healthz"]
    #  interval: 30s
    #  timeout: 10s
    #  retries: 3
    #  start_period: 10s
services:
  n8n_editor:
    image: n8nio/n8n:latest
    command: start

    networks:
      - my_network

    depends_on:
      - redis
      - db

    environment:
      ## Postgres
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_HOST=db
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_USER=postgres
      - DB_POSTGRESDB_PASSWORD=teste

      ## Encryption Key
      - N8N_ENCRYPTION_KEY=a3f8a5d91b9d67f72e5f0dc3a72534d6

      ## N8N
      - N8N_HOST=localhost
      - N8N_EDITOR_BASE_URL=http://localhost:5678/
      - WEBHOOK_URL=http://localhost:5678/
      - N8N_PROTOCOL=http

      ## Node mode
      - NODE_ENV=production

      ## Execution node
      - EXECUTIONS_MODE=queue

      ## Community Nodes
      - N8N_REINSTALL_MISSING_PACKAGES=true
      - N8N_COMMUNITY_PACKAGES_ENABLED=true
      - N8N_NODE_PATH=/home/node/.n8n/nodes
      - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true

      ## SMTP
      - N8N_SMTP_SENDER=
      - N8N_SMTP_HOST=
      - N8N_SMTP_PORT=
      - N8N_SMTP_USER=
      - N8N_SMTP_PASS=
      - N8N_SMTP_SSL=true

      ## Redis
      - QUEUE_BULL_REDIS_HOST=redis
      - QUEUE_BULL_REDIS_PORT=6379
      - QUEUE_BULL_REDIS_DB=2

      - NODE_FUNCTION_ALLOW_EXTERNAL=moment,lodash,moment-with-locales
      - EXECUTIONS_DATA_PRUNE=true
      - EXECUTIONS_DATA_MAX_AGE=336

      ## Timezone
      - GENERIC_TIMEZONE=America/Sao_Paulo
      - TZ=America/Sao_Paulo

    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5678/healthz"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s


  n8n_webhook:
    image: n8nio/n8n:latest
    command: webhook

    networks:
      - my_network
    
    depends_on:
      - redis
      - db

    environment:
      ## Postgres
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_HOST=db
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_USER=postgres
      - DB_POSTGRESDB_PASSWORD=teste

      ## Encryption Key
      - N8N_ENCRYPTION_KEY=a3f8a5d91b9d67f72e5f0dc3a72534d6

      ## N8N
      - N8N_HOST=localhost
      - N8N_EDITOR_BASE_URL=http://localhost:5678/
      - WEBHOOK_URL=http://localhost:5678/
      - N8N_PROTOCOL=http

      ## Node mode
      - NODE_ENV=production

      ## Execution node
      - EXECUTIONS_MODE=queue

      ## Community Nodes
      - N8N_REINSTALL_MISSING_PACKAGES=true
      - N8N_COMMUNITY_PACKAGES_ENABLED=true
      - N8N_NODE_PATH=/home/node/.n8n/nodes
      - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true

      ## SMTP
      - N8N_SMTP_SENDER=
      - N8N_SMTP_HOST=
      - N8N_SMTP_PORT=
      - N8N_SMTP_USER=
      - N8N_SMTP_PASS=
      - N8N_SMTP_SSL=true

      ## Redis
      - QUEUE_BULL_REDIS_HOST=redis
      - QUEUE_BULL_REDIS_PORT=6379
      - QUEUE_BULL_REDIS_DB=2

      - NODE_FUNCTION_ALLOW_EXTERNAL=moment,lodash,moment-with-locales
      - EXECUTIONS_DATA_PRUNE=true
      - EXECUTIONS_DATA_MAX_AGE=336

      ## Timezone
      - GENERIC_TIMEZONE=America/Sao_Paulo
      - TZ=America/Sao_Paulo

  n8n_worker:
    image: n8nio/n8n:latest
    command: worker --concurrency=10

    networks:
      - my_network

    depends_on:
      - redis
      - db

    environment:
      ## Postgres
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_HOST=db
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_USER=postgres
      - DB_POSTGRESDB_PASSWORD=teste

      ## Encryption Key
      - N8N_ENCRYPTION_KEY=a3f8a5d91b9d67f72e5f0dc3a72534d6

      ## N8N
      - N8N_HOST=localhost
      - N8N_EDITOR_BASE_URL=http://localhost:5678/
      - WEBHOOK_URL=http://localhost:5678/
      - N8N_PROTOCOL=http

      ## Node mode
      - NODE_ENV=production

      ## Execution node
      - EXECUTIONS_MODE=queue

      ## Community Nodes
      - N8N_REINSTALL_MISSING_PACKAGES=true
      - N8N_COMMUNITY_PACKAGES_ENABLED=true
      - N8N_NODE_PATH=/home/node/.n8n/nodes
      - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true

      ## SMTP
      - N8N_SMTP_SENDER=
      - N8N_SMTP_HOST=
      - N8N_SMTP_PORT=
      - N8N_SMTP_USER=
      - N8N_SMTP_PASS=
      - N8N_SMTP_SSL=true

      ## Redis
      - QUEUE_BULL_REDIS_HOST=redis
      - QUEUE_BULL_REDIS_PORT=6379
      - QUEUE_BULL_REDIS_DB=2

      - NODE_FUNCTION_ALLOW_EXTERNAL=moment,lodash,moment-with-locales
      - EXECUTIONS_DATA_PRUNE=true
      - EXECUTIONS_DATA_MAX_AGE=336

      ## Timezone
      - GENERIC_TIMEZONE=America/Sao_Paulo
      - TZ=America/Sao_Paulo

  db:
    image: postgres:15
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=teste
      - POSTGRES_DB=n8n  # This will create the 'n8n' database automatically
      - PG_MAX_CONNECTIONS=500

    healthcheck:
      test: ["CMD", "pg_isready", "-U", "postgres"]
      interval: 10s
      timeout: 5s
      retries: 5

    networks:
      - my_network

    ports:
      - 5432:5432
    
    volumes:
      - postgres_data:/var/lib/postgresql/data

  redis:
    image: redis:6
    command: [
        "redis-server",
        "--appendonly",
        "yes",
        "--port",
        "6379"
    ]
    volumes:
      - redis_data:/data

    networks:
      - my_network

volumes:
  postgres_data:
  redis_data:

networks:
  my_network:
    name: my_network

I think you’re just missing enabling the endpoint :

add this env var for your worker :

healthz

QUEUE_HEALTH_CHECK_ACTIVE=true

By default this is false, so /healthz will return 404 unless you turn it on

Also watch for the port you’re exposing to perform the check

1 Like