### **Docker CLI example**: ```bash docker run -it --rm \ -p 5678:5678 \ -v ~/.n8n:/home/node/.n8n \ -e N8N_BASIC_AUTH_USER=admin \ -e N8N_BASIC_AUTH_PASSWORD=yourpassword \ n8nio/n8n ``` This runs n8n, persists data to `~/.n8n`, and sets basic auth. ---
# Verdict * ✅ **Use `npm` install** if: * You're prototyping locally. * You're not familiar with Docker yet. * You want minimal setup on your own laptop or dev machine. * ✅ **Use Docker** if: * You're deploying to production. * You want consistent environment isolation. * You need better control over persistence, versions, and networking.
# npm vs Docker: Pros and Cons | Feature / Concern | `npm install -g n8n` | Docker | | ------------------------- | ------------------------------------- | -------------------------------------- | | **Ease of install** | ✅ Very simple | ⚠️ Requires Docker setup | | **Runs natively** | ✅ Yes | ❌ Runs in a container | | **Environment isolation** | ❌ Shares system env | ✅ Fully isolated from system config | | **Version control** | ⚠️ Global package can conflict | ✅ Easily pin to any version | | **Persistence** | ✅ Files stored in local `.n8n` | ✅ Mounted volume makes it explicit | | **Security** | ⚠️ Must secure yourself (auth, HTTPS) | ✅ Can be locked down in container | | **Scalability/Prod use** | ❌ Not ideal for production | ✅ Preferred for production deployments | | **Auto-restart** | ❌ Requires setup (e.g. PM2) | ✅ Use `docker restart` policies | ---