setup n8n on raspberry pi 4

n8nraspberrypiself hosted

Getting Started

Flash your raspberry pi with the OS of your choice

Update

Perform the standar system updates as required


sudo apt update && sudo apt upgrade

Installing Docker

You can find the official documentation of installing docker for your respective OS over here

I flashed Raspbian OS lite so I will be following the debian setup.
Now I would recommend instead of pasting such a huge command in your terminal :

# Add Docker's official GPG key:
sudo apt update
sudo apt install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/debian
Suites: $(. /etc/os-release && echo "$VERSION_CODENAME")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF

sudo apt update

create a .sh file first (something like install_docker.sh) make it an executable


sudo chmod u+x ./insatll_docker.sh

and then run it :


./install_docker.sh

after this we install the actual docker packages :


sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Now usually the docker service should start running automoatically by itself but if you are the paranoid type and want to verify it yourself you can run :


sudo systemctl status docker

Incase your paranoia actually worked and the docker daemon has not started you can start it like this :


sudo systemctl start docker

And finally to verify if docker is working run hello-world image of docker


sudo docker run hello-world

Setup n8n

Now finally getting to the exciting part of all this actually running an n8n container with docker-compose. Firstly for that create a docker-compose.yml file in whichever directory you would like. After that open the file with your choice of text editor and paste the following yaml config

version: '3.8'

services:
  n8n:
    image: n8nio/n8n
    restart: always
    ports:
      - "5678:5678"
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=db
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_USER=n8n
      - DB_POSTGRESDB_PASSWORD=n8n_password
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=user
      - N8N_BASIC_AUTH_PASSWORD=password
      - N8N_EDITOR_BASE_URL=http://localhost:5678/
      - VUE_APP_URL_BASE_API=http://localhost:5678/
      - N8N_SECURE_COOKIE=false
    volumes:
      - n8n_data:/home/node/.n8n
    depends_on:
      - db

  db:
    image: postgres:12
    restart: always
    environment:
      - POSTGRES_DB=n8n
      - POSTGRES_USER=n8n
      - POSTGRES_PASSWORD=n8n_password
    volumes:
      - postgres_data:/var/lib/postgresql/data

volumes:
  n8n_data:
  postgres_data:

Now one of the most important points to note here is this setting in the config :


      - N8N_SECURE_COOKIE=false

This disables any encryption that is applied on cookies so this is fine if you are accesing this over localhost or even just over your local network but if you plan on exposing this over the internet I would recommend removing this option.

Now to finally access this we can go over to our raspberry pi’s ip on port 5678 like this :


http://<ip-address>:5678

and you should be greeted with the n8n setup page.