n8n Self-hosted AI Starter Kit

repository·main·Indexed 12 days ago

https://github.com/n8n-io/self-hosted-ai-starter-kit

A Docker Compose-based starter kit for deploying a local AI development environment. It integrates n8n for low-code automation, Ollama for local LLMs, Qdrant as a vector database, and PostgreSQL for relational data. Includes hardware-specific profiles for Nvidia GPU, AMD GPU, and CPU-only setups, as well as configuration guides for Mac/Apple Silicon.

Tokens
1.7K
Snippets
8
Records
10
Agent score
47%

What's inside n8n Self-hosted AI Starter Kit

  1. Access local files from n8n nodes

    main

    The starter kit mounts a shared folder from your host machine into the n8n container. This allows n8n to read and write files on your local disk.

    • Container Path: /data/shared
    • Usage: Use this path in nodes that interact with the filesystem.

    Compatible Nodes:

    • Read/Write Files from Disk
    • Local File Trigger
    • Execute Command
  2. Run the Starter Kit with Docker Compose profiles

    main

    Depending on your hardware, use the appropriate Docker Compose profile to run the stack:

    • Nvidia GPU users: Use the gpu-nvidia profile.
    • AMD GPU users on Linux: Use the gpu-amd profile.
    • Everyone else (CPU only): Use the cpu profile.

    Note: If using Nvidia, ensure you have followed the Ollama Docker instructions if you haven't used Nvidia GPUs with Docker before.

    # For Nvidia GPU
    docker compose --profile gpu-nvidia up
    
    # For AMD GPU on Linux
    docker compose --profile gpu-amd up
    
    # For CPU only
    docker compose --profile cpu up
  3. Quick start guide for n8n workflows

    main

    Once the containers are running:

    1. Access n8n at http://localhost:5678/ to perform the initial setup.
    2. Open the included demo workflow at http://localhost:5678/workflow/srOnR8PAY3u4RSwb.
    3. Click the Chat button at the bottom of the canvas to interact with the workflow.
    4. Note: If it's your first run, Ollama may be downloading models (like Llama3.2) in the background. You can check progress via docker console logs.
  4. Install the Self-hosted AI Starter Kit

    main

    The Self-hosted AI Starter Kit is a Docker Compose template that sets up a local AI development environment including n8n, Ollama, Qdrant, and PostgreSQL.

    To install, clone the repository and initialize your environment variables:

    1. Clone the repo.
    2. Navigate to the directory.
    3. Copy the example .env file and update any secrets or passwords.
    git clone https://github.com/n8n-io/self-hosted-ai-starter-kit.git
    cd self-hosted-ai-starter-kit
    cp .env.example .env # you should update secrets and passwords inside
  5. Upgrade the Self-hosted AI Starter Kit

    main

    To upgrade your installation to the latest images, use the following commands based on your setup:

    • Nvidia GPU: Pull images, then recreate and start.
    • Mac/Apple Silicon: Pull images, then recreate and start.
    • Non-GPU (CPU): Pull images using the cpu profile, then recreate and start.
    # For Nvidia GPU
    docker compose --profile gpu-nvidia pull
    docker compose create && docker compose --profile gpu-nvidia up
    
    # For Mac / Apple Silicon
    docker compose pull
    docker compose create && docker compose up
    
    # For Non-GPU setups
    docker compose --profile cpu pull
    docker compose create && docker compose --profile cpu up
  6. Configure Ollama on Mac/Apple Silicon

    main

    On Mac with M1/newer processors, you cannot expose the GPU to Docker. You have two options:

    Option 1: Run fully on CPU

    Use the cpu profile as described in the 'Everyone else' section.

    Option 2: Run Ollama locally on Mac for faster inference

    1. Install Ollama directly on your Mac via the Ollama homepage.
    2. In your .env file, set OLLAMA_HOST to host.docker.internal:11434.
    3. Start the kit using docker compose up (without a profile).
    4. In n8n (http://localhost:5678/), go to Credentials -> Local Ollama service and change the Base URL to http://host.docker.internal:11434/.
    # After setting OLLAMA_HOST in .env
    docker compose up
  7. Select Ollama hardware profile

    main

    The starter kit uses Docker Compose profiles to allow you to choose the appropriate Ollama runtime based on your hardware. You must specify the profile when running your docker commands.

    Available profiles:

    • cpu: Runs Ollama on the CPU.
    • gpu-nvidia: Runs Ollama with NVIDIA GPU support (requires NVIDIA Container Toolkit).
    • gpu-amd: Runs Ollama with AMD GPU support using the ollama/ollama:rocm image.
    # Example: Running with NVIDIA GPU support
    docker compose --profile gpu-nvidia up -d
    
    # Example: Running with CPU only
    docker compose --profile cpu up -d
    
    # Example: Running with AMD GPU support
    docker compose --profile gpu-amd up -d
  8. Configure n8n environment variables

    main

    The n8n service uses several environment variables for database connectivity, security, and AI integration. These should be defined in your .env file. Note that N8N_ENCRYPTION_KEY and N8N_USER_MANAGEMENT_JWT_SECRET are required for security and persistence.

    Key variables include:

    • DB_TYPE: Set to postgresdb.
    • DB_POSTGRESDB_HOST: Set to postgres.
    • DB_POSTGRESDB_USER: Uses ${POSTGRES_USER} from .env.
    • DB_POSTGRESDB_PASSWORD: Uses ${POSTGRES_PASSWORD} from .env.
    • N8N_ENCRYPTION_KEY: Required for encrypting credentials.
    • N8N_USER_MANAGEMENT_JWT_SECRET: Required for user management.
    • OLLAMA_HOST: The address of the Ollama instance (defaults to ollama:11434).
    POSTGRES_USER=your_user
    POSTGRES_PASSWORD=your_password
    POSTGRES_DB=n8n
    N8N_ENCRYPTION_KEY=your_encryption_key
    N8N_USER_MANAGEMENT_JWT_SECRET=your_jwt_secret
    OLLAMA_HOST=ollama:11434
  9. Reference: n8n Environment Variables

    main

    The following environment variables are used by the n8n service in the docker-compose.yml configuration.

    DB_TYPE
    DB_POSTGRESDB_HOST
    DB_POSTGRESDB_USER
    DB_POSTGRESDB_PASSWORD
    N8N_DIAGNOSTICS_ENABLED
    N8N_PERSONALIZATION_ENABLED
    N8N_ENCRYPTION_KEY
    N8N_USER_MANAGEMENT_JWT_SECRET
    OLLAMA_HOST