Should worker and main share the same docker volume?

I’ve been using this example for my server:

version: '3.8'

volumes:
  db_storage:
  n8n_storage:
  redis_storage:

x-shared: &shared
  restart: always
  environment:
    - DB_TYPE=postgresdb
    - DB_POSTGRESDB_HOST=postgres
    - DB_POSTGRESDB_PORT=5432
    - DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
    - DB_POSTGRESDB_USER=${POSTGRES_NON_ROOT_USER}
    - DB_POSTGRESDB_PASSWORD=${POSTGRES_NON_ROOT_PASSWORD}
    - EXECUTIONS_MODE=queue
    - QUEUE_BULL_REDIS_HOST=redis
    - QUEUE_HEALTH_CHECK_ACTIVE=true
    - N8N_BASIC_AUTH_ACTIVE=false
    - N8N_PROTOCOL=https
    - VUE_APP_URL_BASE_API=https://${N8N_HOST}
    - WEBHOOK_TUNNEL_URL=https://${N8N_HOST}
  links:
    - postgres
    - redis
  volumes:
    - n8n_storage:/home/node/
  depends_on:
    redis:
      condition: service_healthy
    postgres:
      condition: service_healthy

services:
  https-portal:
    image: steveltn/https-portal:1
    ports:
      - '80:80'
      - '443:443'
    links:
      - n8n
    restart: always
    environment:
      DOMAINS: '${N8N_HOST} -> http://n8n:5678'
      STAGE: ${STAGE:-staging}
      FORCE_RENEW: 'true'
      CUSTOM_NGINX_SERVER_CONFIG_BLOCK: |
          proxy_buffering off;

  postgres:
    image: postgres:11
    restart: always
    environment:
      - POSTGRES_USER
      - POSTGRES_PASSWORD
      - POSTGRES_DB
      - POSTGRES_NON_ROOT_USER
      - POSTGRES_NON_ROOT_PASSWORD
    volumes:
      - db_storage:/var/lib/postgresql/data
      - ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -h localhost -U ${POSTGRES_USER} -d ${POSTGRES_DB}']
      interval: 5s
      timeout: 5s
      retries: 10

  redis:
    image: redis:6-alpine
    restart: always
    volumes:
      - redis_storage:/data
    healthcheck:
      test: ['CMD', 'redis-cli', 'ping']
      interval: 5s
      timeout: 5s
      retries: 10

  n8n:
    <<: *shared
    image: n8nio/n8n
    command: /bin/sh -c "n8n start"
    # ports:
    #  - 5678:5678

  n8n-worker:
    <<: *shared
    image: n8nio/n8n
    command: /bin/sh -c "sleep 5; n8n worker"
    depends_on:
      - n8n

I’ve noticed that the main and worker share the exat same volume. when I gave the worker its own volume though it silently failed to start (no logs)

Any ideas how this should be handled? Is this example correct?

@Cosku where did you find this?

Typucally no and tbh most data is st9red in db so only enc key is there and mysqllite if not using postgress etc

Samuel

I had to resort to this: n8n-docker/docker-compose.yml at master · danilopinotti/n8n-docker · GitHub
Since n8n has zero documentation on how to use docker-compose for any kind of production environment (with workers)

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