Docker configuration for multi n8n

I would like to have several containers with n8n using docker.
Here is my configuration.

The problem is that I have a bad gateway on the 2nd container, and after analysing the logs. It’s still running on the default port (5678)

What’s wrong with my configuration?

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

do you mean n8n main and then n8n workers, or several seperate versions of n8n?

Hey @GregM, Could you please check https://community.n8n.io/t/running-multiple-n8n-instances-on-a-self-hosted-server/35852/4, I believe you could use my docker-compose file as guidance, with or without traefik based on your situation.

1 Like

Hello,

Thank you for your comments. I’ve found the answer while waiting for my account to be validated.

here’s a conf that may be useful to others

version: "3.7"

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:
      - traefik_fs:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock:ro

  n8nwps:
    image: docker.n8n.io/n8nio/n8n
    container_name: wps
    restart: always
    ports:
      - "127.0.0.1:5650:5678"
    labels:
      - traefik.enable=true
      - traefik.http.routers.n8nwps.rule=Host(`${SUBDOMAIN_WPS}.${DOMAIN_NAME_WPS}`)
      - traefik.http.routers.n8nwps:q.tls=true
      - traefik.http.routers.n8nwps.entrypoints=web,websecure
      - traefik.http.routers.n8nwps.tls.certresolver=mytlschallenge
      - traefik.http.routers.n8nwps.middlewares=n8nwps@docker
      - traefik.http.middlewares.n8nwps.headers.SSLRedirect=true
      - traefik.http.middlewares.n8nwps.headers.STSSeconds=315360000
      - traefik.http.middlewares.n8nwps.headers.browserXSSFilter=true
      - traefik.http.middlewares.n8nwps.headers.contentTypeNosniff=true
      - traefik.http.middlewares.n8nwps.headers.forceSTSHeader=true
      - traefik.http.middlewares.n8nwps.headers.SSLHost=${DOMAIN_NAME_WPS}
      - traefik.http.middlewares.n8nwps.headers.STSIncludeSubdomains=true
      - traefik.http.middlewares.n8nwps.headers.STSPreload=true
      - traefik.http.middlewares.myauth.basicauth.usersfile=./n8nwps.txt
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_HOST=${SUBDOMAIN_WPS}.${DOMAIN_NAME_WPS}
      - N8N_PORT=5678
      - NODE_FUNCTION_ALLOW_EXTERNAL=cheerio
      - N8N_LOG_LEVEL=error
      - N8N_LOG_OUTPUT=console,file
      - N8N_LOG_FILE_LOCATION=/home/node/log/n8nwps.log
      - N8N_LOG_FILE_MAXSIZE=50
      - N8N_LOG_FILE_MAXCOUNT=60
      - N8N_TEMPLATES_ENABLED=false
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://${SUBDOMAIN_WPS}.${DOMAIN_NAME_WPS}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /root/docker/n8n/shared:/home/node/shared
      - /root/docker/n8n/log:/home/node/log
      - n8n_wps:/home/node/.n8n
      - /local-files:/files
      - ./config/n8nwps.txt:/n8nwps.txt:ro
  n8npp:
    image: docker.n8n.io/n8nio/n8n
    container_name: pp
    restart: always
    ports:
      - "127.0.0.1:5690:5678"
    labels:
      - traefik.enable=true
      - traefik.http.routers.n8npp.rule=Host(`${SUBDOMAIN_PP}.${DOMAIN_NAME_PP}`)
      - traefik.http.routers.n8npp:q.tls=true
      - traefik.http.routers.n8npp.entrypoints=web,websecure
      - traefik.http.routers.n8npp.tls.certresolver=mytlschallenge
      - traefik.http.routers.n8npp.middlewares=n8npp@docker
      - traefik.http.middlewares.n8npp.headers.SSLRedirect=true
      - traefik.http.middlewares.n8npp.headers.STSSeconds=315360000
      - traefik.http.middlewares.n8npp.headers.browserXSSFilter=true
      - traefik.http.middlewares.n8npp.headers.contentTypeNosniff=true
      - traefik.http.middlewares.n8npp.headers.forceSTSHeader=true
      - traefik.http.middlewares.n8npp.headers.SSLHost=${DOMAIN_NAME_PP}
      - traefik.http.middlewares.n8npp.headers.STSIncludeSubdomains=true
      - traefik.http.middlewares.n8npp.headers.STSPreload=true
      - traefik.http.middlewares.myauth.basicauth.usersfile=./n8npp.txt
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_HOST=${SUBDOMAIN_PP}.${DOMAIN_NAME_PP}
      - N8N_LOG_LEVEL=error
      - N8N_LOG_OUTPUT=console,file
      - N8N_LOG_FILE_LOCATION=/home/node/share/n8npp.log
      - N8N_LOG_FILE_MAXSIZE=50
      - N8N_LOG_FILE_MAXCOUNT=60
      - N8N_PORT=5678
      - NODE_FUNCTION_ALLOW_EXTERNAL=cheerio
      - N8N_TEMPLATES_ENABLED=false
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://${SUBDOMAIN_PP}.${DOMAIN_NAME_PP}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - n8n_pp:/home/node/.n8n
      - /root/docker/n8n/shared:/home/node/shared
      - /root/docker/n8n/log:/home/node/log
      - /local-files:/files
      - ./config/n8npp.txt:/n8npp.txt:ro

volumes:
  traefik_fs:
    external: true
  n8n_wps:
    external: true
  n8n_pp:
    external: true

Don’t hesitate to post comments to improve this configuration

1 Like