n8n Docker Installation

Overview

  • System used: Debian 12 64-bit
  • User account: I am performing all steps as ‘root’
  • Duration: approx. 5 minutes
  • Difficulty: Easy. Just copy the code 😉
  • Special features:

Full control with your own VPS from easyname

With a VPS from easyname, you have full control over your server – flexible, scalable and operated in an environmentally conscious manner in ISO-certified data centres in Austria. Ideal for your applications, projects and maximum performance.

Close-up of a blue-lit server rack with multiple drive bays and front-panel indicators.

Installing n8n

1.1 Introduction

In the world of automation tools, n8n has quickly evolved from an insider tip to one of the most powerful platforms. Unlike closed systems, n8n follows a ‘fair code’ approach. This means that the source code is available, and the tool can either be used in the cloud or – which is crucial for data protection and flexibility – hosted on your own server.

1.2 Information on YML files

With YML files, it is very important that all lines are correctly indented. Lines MUST always be indented using the space bar. They must NOT contain any tabs. You can always have the following code ‘checked’ online. Most errors are caused by incorrect formatting. One service for checking is, for example: https://codebeautify.org/yaml-validator

1.3 Preparation

These instructions are based on the current Debian 12 operating system. We will set up n8n using Docker. This will allow us to perform very quick updates and a fast installation later on.

To run n8n alongside other services on our server, we’ll be using the Traefik reverse proxy. You can find the guide for this here:  Installing Traefik reverse proxy on a VPS

1.3.1 Create a directory

We will create a new directory in which we will later store all n8n data. To do this, enter the following in the console:

mkdir -p /opt/containers/n8n

You can also use a different directory here. However, you will then need to adapt the entire guide accordingly.

1.3.2 Create docker-compose.yml

Now we can begin the actual “installation” of n8n. To do this, open the following file:

nano /opt/containers/n8n/docker-compose.yml

Now copy the following code into the file. This code is our blueprint for our n8n container.

services:
  n8n-postgres:
    image: postgres:16
    restart: unless-stopped
    env_file:
      - ./.env
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_NON_ROOT_USER=${POSTGRES_NON_ROOT_USER}
      - POSTGRES_NON_ROOT_PASSWORD=${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
    networks:
      - default
  n8n:
    image: docker.n8n.io/n8nio/n8n
    restart: unless-stopped
    env_file:
      - ./.env
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=n8n-postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
      - DB_POSTGRESDB_USER=${POSTGRES_NON_ROOT_USER}
      - DB_POSTGRESDB_PASSWORD=${POSTGRES_NON_ROOT_PASSWORD}
    links:
      - n8n-postgres
    volumes:
      - n8n_storage:/home/node/.n8n
    depends_on:
      n8n-postgres:
        condition: service_healthy
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.n8n.entrypoints=http"
      - "traefik.http.routers.n8n.rule=Host(`n8n.euredomain.de`)"
      - "traefik.http.middlewares.n8n-https-redirect.redirectscheme.scheme=https"
      - "traefik.http.routers.n8n.middlewares=n8n-https-redirect"
      - "traefik.http.routers.n8n-secure.entrypoints=https"
      - "traefik.http.routers.n8n-secure.rule=Host(`n8n.euredomain.de`)"
      - "traefik.http.routers.n8n-secure.tls=true"
      - "traefik.http.routers.n8n-secure.tls.certresolver=http"
      - "traefik.http.routers.n8n-secure.service=n8n"
      - "traefik.http.services.n8n.loadbalancer.server.port=5678"
      - "traefik.docker.network=proxy"
      - "traefik.http.routers.n8n-secure.middlewares=secHeaders@file"
    networks:
      - proxy
      - default
networks:
  proxy:
    external: true
 
volumes:
  db_storage:
  n8n_storage:

1.3.3 Customise the hostname

Now you need to customise the hostname through which n8n will be accessible later.

You need to adjust these two lines.

   - "traefik.http.routers.n8n.rule= Host(`n8n.yourdomain.com`)"
    - "traefik.http.routers.n8n-secure.rule= Host(`n8n.yourdomain.com`)"

In my case, therefore:

   - "traefik.http.routers.n8n.rule= Host(`n8n.testbereich.net`)"
    - "traefik.http.routers.n8n-secure.rule= Host(`n8n.testbereich.net`)"

1.3.4 Creating a configuration file

Now we’ll create a configuration file containing important information about the database. To do this, enter the following:

nano /opt/containers/n8n/.env

Content:

POSTGRES_USER=changeUser
POSTGRES_PASSWORD=changePassword
POSTGRES_DB=n8n
POSTGRES_NON_ROOT_USER=changeUser
POSTGRES_NON_ROOT_PASSWORD=changePassword

You can now customise these details as required.

1.3.5 Create a database initialisation script

Now we need a script that initialises the database for us on first start-up. To do this, enter the following:

nano /opt/containers/n8n/init-data.sh

Content:

#!/bin/bash
set -e;
if [ -n "${POSTGRES_NON_ROOT_USER:-}" ] && [ -n "${POSTGRES_NON_ROOT_PASSWORD:-}" ]; then
        psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
                CREATE USER ${POSTGRES_NON_ROOT_USER} WITH PASSWORD '${POSTGRES_NON_ROOT_PASSWORD}';
                GRANT ALL PRIVILEGES ON DATABASE ${POSTGRES_DB} TO ${POSTGRES_NON_ROOT_USER};
                GRANT CREATE ON SCHEMA public TO ${POSTGRES_NON_ROOT_USER};
EOSQL
else
        echo "SETUP INFO: No environment variables provided!"
fi

Start n8n

Now enter the following to start your n8n container:

docker compose -f /opt/containers/n8n/docker-compose.yml up -d

When the container is started for the first time, n8n is initialised. This means that the database is set up, your settings are applied, and much more. It therefore takes a few minutes before the container is accessible via the website (e.g. n8n.testarea.net).

2.1 Setting up n8n

You will now be prompted to create a user. Enter your personal details here.

Signup form card with Email, First Name, Last Name, Password fields, password note, a checkbox, and Next button.

Now you’ll be asked a few more questions about yourselves.

You can skip this by clicking on ‘Get started’. In the final step, you can now register with the manufacturer so that you can activate additional features.

Web page titled 'Get paid features for free (forever)' with three features, email input, and orange 'Send me a free license key' button.

You can skip this step by clicking ‘Skip’. n8n is now set up.

White UI screen with welcome message, central 'Start from scratch' card, bottom row of template cards, and left toolbar.

Full control with your own VPS from easyname

With a VPS from easyname, you have full control over your server – flexible, scalable and operated in an environmentally conscious manner in ISO-certified data centres in Austria. Ideal for your applications, projects and maximum performance.

Close-up of a blue-lit server rack with multiple drive bays and front-panel indicators.