How to Install and Run n8n with Docker: The Resilient Way
Hey FutureFormDigital community! 👋
If you’re tired of piecing together workflows through manual effort or expensive, restrictive SaaS tools, you’ve probably heard of n8n. It’s an absolute powerhouse for workflow automation, and the best part? You can self-host it to own your data and processes entirely.
But self-hosting can be a headache if you don’t do it right. You don’t want to wake up to a broken integration because an update went sideways. The solution? Docker. Running n8n in a container makes your automation environment portable, reproducible, and incredibly easy to manage.
Let’s cut through the noise and get you set up with a production-grade n8n instance that actually lasts.
Why Docker is the Only Way to Go
If you’re still trying to install n8n directly on your VPS, stop. You’re making life harder than it needs to be. Docker isolates n8n from your OS, meaning upgrades don’t break your system dependencies, and you can move your entire workflow environment from one server to another in minutes.
| Feature | docker run (The Sandbox) | docker-compose (The Pro Way) |
|---|---|---|
| Use Case | Quick tests, learning | Production, heavy usage |
| Complexity | Extremely Low | Low |
| Persistence | Requires explicit volumes | Native, configured in YAML |
| Scalability | Not recommended | Excellent (Easy to add DBs, proxies) |
“Docker isn’t just about ‘getting it to work.’ It’s about ‘getting it to work the same way’ every single time you deploy.”
Option 1: The Quick Sandbox (docker run)
If you just want to see how n8n works, use this command. Warning: Do not use this in production.
docker volume create n8n_data
docker run -it --rm
--name n8n
-p 5678:5678
-v n8n_data:/home/node/.n8n
docker.n8n.io/n8nio/n8n
This starts a container, maps port 5678, and keeps your workflows safe in a volume. If you stop the container with --rm, the container is removed, but your data inside n8n_data remains.
Option 2: The Production Standard (docker-compose)
For anyone actually running workflows for their business, Docker Compose is non-negotiable. It lets you manage your n8n container, database, and configurations in one clean file.
Step 1: Prepare Your Directory
mkdir ~/n8n && cd ~/n8n
mkdir n8n_data
sudo chown -R 1000:1000 n8n_data
Step 2: Create docker-compose.yml
Create the file with nano docker-compose.yml and paste this (customize your credentials!):
services:
n8n:
image: docker.n8n.io/n8nio/n8n:1.95.0
restart: unless-stopped
ports:
- "5678:5678"
environment:
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=admin
- N8N_BASIC_AUTH_PASSWORD=yourStrongPassword
- N8N_HOST=localhost
- WEBHOOK_URL=http://localhost:5678/
- GENERIC_TIMEZONE=UTC
volumes:
- ./n8n_data:/home/node/.n8n
Step 3: Launch
docker compose up -d
Access your dashboard at http://localhost:5678 (or your server IP).
Production Gotchas: Don’t Get Burned
- Persistence is everything: Always map a volume (
-v ./n8n_data:/home/node/.n8n). If you don’t, losing the container means losing every single workflow you’ve built. - Database Matters: For heavy production use, switch from the default SQLite to PostgreSQL. SQLite is fine for testing, but it will corrupt under heavy concurrent webhook load.
- Reverse Proxy & SSL: Never expose port 5678 directly to the public internet. Put it behind NGINX or Caddy. Caddy is our recommendation because it handles Let’s Encrypt SSL certificates automatically.
- Version Pinning: Crucial! In your
docker-compose.yml, never useimage: n8nio/n8n:latest. Always pin a specific version (e.g.,:1.95.0). This stops your instance from automatically upgrading and potentially breaking production workflows overnight.
FutureFormDigital Insight: Our Recommendation
If you are running n8n to support actual business processes, do not cut corners. Use Docker Compose + PostgreSQL + Caddy.
It might take 30 minutes to set up instead of 5 minutes, but the reliability of having a database that handles concurrency and a reverse proxy that handles SSL automatically is worth every second. If you don’t have the capacity to maintain a VPS (backups, updates, security), honestly, just pay for n8n Cloud. It’s cheaper than the on-call service you’d have to pay if a self-hosted instance dies at 3 AM.
FAQ: Frequently Asked Questions
Q1: Is n8n free to use?
A1: Yes, n8n is open source and free to self-host. There are paid plans for Enterprise features and Cloud hosting.
Q2: What is the default port?
A2: n8n runs on port 5678 by default.
Q3: Can I run n8n on Windows/Mac?
A3: Yes, for local development, but use a Linux VPS for any production workload.
Q4: How do I update n8n?
A4: Update the image version in your docker-compose.yml, then run docker compose pull followed by docker compose up -d.
Q5: Why should I switch to PostgreSQL?
A5: SQLite is prone to file-locking and corruption under concurrent load; PostgreSQL is built for production reliability.
Q6: What is a reverse proxy?
A6: A tool like Caddy or NGINX that sits in front of n8n, handles HTTPS/SSL, and secures your traffic.
Q7: Do I need a domain name?
A7: For production, yes. It makes handling SSL and access much easier.
Q8: How do I back up my workflows?
A8: Back up the volume mapped to /home/node/.n8n AND your Postgres database nightly.
Q9: What are the hardware requirements?
A9: For light workflows, 2 vCPU and 4GB RAM is the sweet spot.
Q10: Can I limit n8n’s resources?
A10: Yes, use the deploy: resources: limits section in your docker-compose.yml to cap CPU and RAM usage.
Your Turn!
Self-hosting n8n is the first step toward true digital independence. Once you have it running, the potential for automating your dullest tasks is endless.
Are you planning to run n8n for personal projects or to automate a business process? Let us know in the comments below!