n n8n

How to install n8n with Docker on n8n

beginner 8 min read Updated 2026-03-13
Quick Answer

Install n8n with Docker by creating a data volume, running the official <code>docker run</code> command mapping port 5678 and mounting <code>n8n_data:/home/node/.n8n</code>, then access http://localhost:5678 for onboarding. Use Docker Compose for production with PostgreSQL. Data persists across restarts via volumes; common issues like port conflicts resolve quickly.

Prerequisites

  • Docker installed and running (verify with <code>docker --version</code>)
  • Port 5678 available on host
  • Basic command-line access
  • 2GB RAM and 2 CPU cores recommended
  • Docker Compose (optional for production)

Step-by-Step Instructions

1

Verify Docker Installation

Ensure Docker is installed and running by executing docker --version and docker run hello-world. On Linux, install via sudo apt update && sudo apt install docker.io -y && sudo systemctl enable --now docker; use Docker Desktop for macOS/Windows. Check port 5678 availability with sudo lsof -i :5678.[1][2][3][4]
2

Create Persistent Data Volume

Run docker volume create n8n_data to create a volume for storing workflows, credentials, and config in /home/node/.n8n inside the container, preventing data loss on restarts.[4]
This step is crucial for persistence; skip only for testing.
3

Run n8n Single-Container (Quick Setup)

docker run -it --rm \
  --name n8n \
  -p 5678:5678 \
  -e GENERIC_TIMEZONE="America/New_York" \
  -e TZ="America/New_York" \
  -e N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true \
  -e N8N_RUNNERS_ENABLED=true \
  -v n8n_data:/home/node/.n8n \
  docker.n8n.io/n8nio/n8n
Replace America/New_York with your timezone (e.g., UTC). This uses SQLite, maps port 5678, enables secure permissions and task runners, and pulls the official image.[4]
Flags <code>-it --rm</code> allow interactive run and auto-cleanup; data safe in volume.
4

Verify Container is Running

Check with docker ps; look for n8n container 'Up' on 0.0.0.0:5678->5678/tcp. View logs via docker logs n8n if issues arise.[1][4]
5

Access n8n UI and Onboard

Open http://localhost:5678 in browser. Complete onboarding by setting up Owner Account (email/password). Navigate to Workflows tab for new automations and Credentials for integrations.[4]
No default auth; set strong credentials immediately.
6

Manage Container (Stop/Start)

Stop with Ctrl+C or docker stop n8n. Restart by re-running the docker run command; data persists via volume. For detached mode, remove -it and add -d.[4]
7

Set Up Docker Compose (Production)

Create docker-compose.yml:
version: '3.1'
services:
  n8n:
    image: docker.n8n.io/n8nio/n8n
    ports:
      - "5678:5678"
    environment:
      - GENERIC_TIMEZONE=UTC
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=strongpass
    volumes:
      - ./n8n_data:/home/node/.n8n
Run docker compose up -d.[1][3]
Add PostgreSQL service for production scaling.
8

Enable Basic Auth and Security

In Compose or run command, add -e N8N_BASIC_AUTH_ACTIVE=true -e N8N_BASIC_AUTH_USER=admin -e N8N_BASIC_AUTH_PASSWORD=strongpass for login protection. Set N8N_REINSTALL_MISSING_PACKAGES=true for community nodes.[1][3]
Essential for exposed instances.
9

Test and Create First Workflow

After access, create a test workflow in the dashboard. Verify persistence by restarting container and checking data remains.[4]
10

Scale to PostgreSQL (Advanced)

Extend Compose with Postgres: add postgres: service and set DB_TYPE=postgresdb, host/user/password vars. Run docker compose up -d.[3]
Use for production; backup DB regularly.

Common Issues & Troubleshooting

Port 5678 already in use

Check with <code>sudo lsof -i :5678</code>, kill process or change host port (e.g., <code>-p 5679:5678</code>).[1][2]

Permission errors on data volume

Fix ownership: <code>sudo chown -R 1000:1000 n8n_data</code> or use named volume.[1]

Missing community nodes/packages

Set <code>N8N_REINSTALL_MISSING_PACKAGES=true</code> in env vars.[1]

DB init failure (e.g., Duplicate column)

Clear volume <code>docker volume rm n8n_data</code> and recreate; ensure env vars match.[1]

Container fails to start

Check logs <code>docker logs n8n</code>; verify Docker resources (2GB RAM min), pull image manually <code>docker pull docker.n8n.io/n8nio/n8n</code>.[2][4]