How to install n8n with Docker on n8n
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
Verify Docker Installation
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]Create Persistent Data Volume
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]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]Verify Container is Running
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]Access n8n UI and Onboard
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]Manage Container (Stop/Start)
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]Set Up Docker Compose (Production)
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]Enable Basic Auth and Security
-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]Test and Create First Workflow
Scale to PostgreSQL (Advanced)
postgres: service and set DB_TYPE=postgresdb, host/user/password vars. Run docker compose up -d.[3]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]