Self-host n8n with Docker in 5 steps on Linux

a golden docker logo on a black background

Cloud automation platforms charge per task, per workflow, or per seat. Once your automations get serious, those bills climb fast. n8n sidesteps all of that with a fair-code license that lets you run it on your own hardware with no usage restrictions. Your only cost is the server.

This guide walks through the full Docker Compose setup on Linux: from a blank server to a running n8n instance with your first workflow editor open in the browser.

What you need before you start

  • A virtual machine, server, or NAS with at least 2 vCPUs and 4GB of RAM. Heavier workloads benefit from more CPU cores and memory.
  • A supported Linux distribution: Ubuntu, Debian, or Raspberry Pi OS all work. CentOS Stream, Fedora, and RHEL are also supported.
  • Access to the Docker and Docker Compose repositories via your distro’s package manager.
  • A managed Kubernetes cluster if you plan to run production-grade workflows (optional).

️ Step 1: Install Docker and Docker Compose

Open your Linux terminal and update your software catalog first:

sudo apt-get update

Then install Docker, Docker Compose, and all required dependencies in one command:

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

Confirm the install worked:

docker --version
docker compose version

️ Step 2: Write your Docker Compose file

Create a dedicated directory for your n8n setup and move into it:

mkdir n8n-compose
cd n8n-compose

Inside that directory, create a .env file with your environment variables:

DOMAIN_NAME=example.com
SUBDOMAIN=n8n
GENERIC_TIMEZONE=Europe/London
[email protected]

Replace those values with your actual domain, time zone, and email. If you are running n8n locally rather than on an external server, remove DOMAIN_NAME, SUBDOMAIN, and SSL_EMAIL. Leave only GENERIC_TIMEZONE.

an electronic device sitting on top of a book

Next, create a compose.yaml file in the same directory:

services:
  n8n:
    image: docker.n8n.io/n8nio/n8n
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    environment:
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - TZ=${GENERIC_TIMEZONE}
    volumes:
      - n8n_data:/home/node/.n8n
      - ./local-files:/files

volumes:
  n8n_data:

This maps n8n to port 5678 on your machine. The Docker volume stores your workflows, credentials, and encryption key. If you are running locally, remove the N8N_HOST, N8N_PROTOCOL, and WEBHOOK_URL lines.

Finally, create the local-files folder that the volume references:

mkdir local-files

Step 3: Launch n8n

Start all containers with one command:

docker compose up -d

After about a minute, check that the containers are running:

docker compose logs -f n8n

Open https://localhost:5678 in any browser. If your instance is up, you will see the account creation screen.

️ Step 4: Create your n8n account

The first time you open the editor, n8n asks you to register. Enter your email, your name, and a password that includes at least one capital letter and one number. The account you create here becomes the instance owner, which functions like a super-admin with full access to every workflow and credential.

If other people will use this instance, set up member-level accounts separately so you can track changes per user.

️ Step 5: Build your first workflow

Person planting a houseplant and checking phone

The n8n workflow editor is a node-based visual interface: think flowchart with triggers and actions. If you have used Zapier or Make before, the basics will feel familiar within a few minutes.

Use the Execute step button to test individual nodes during editing. Once everything checks out, save the workflow and toggle it on to keep it active.

Common questions

Is n8n actually open source?

n8n is not open source in the traditional sense. It uses a fair-code license that lets you run it free for personal use or internal business workflows. If you want to commercialize it as a consumer-facing product, you need a paid commercial license.

What does self-hosting actually cost?

Your only ongoing expense is the server. If you have a local machine powerful enough to run the workflows, that cost drops to zero. Compared to cloud-based automation platforms with per-task billing, the savings compound quickly once your workflow volume grows.

Which database does n8n use?

Every n8n installation includes SQLite by default. That is fine for personal or internal use. For production workflows with multiple users, switching to PostgreSQL is recommended since it handles complex concurrent workloads better.

How do you keep the instance secure?

Run n8n over HTTPS, not plain HTTP. If your server is on a shared network, keep your encryption keys out of the .env file. The article recommends using a secret manager like Azure Key Vault or Google Cloud Secret Manager to prevent API keys from being exposed in plain text source code.

Stay on top of AI & Automation with BizStack Newsletter
BizStack  —  Entrepreneur’s Business Stack
Logo