
Module 2 Lesson 1: Running n8n with Docker
The preferred way. Learn how to pull the n8n Docker image and setup a persistent container using Docker Compose for your home or business server.
Module 2 Lesson 1: Running n8n with Docker
Docker is the industry standard for self-hosting. It ensures that n8n runs in a clean environment and makes updating to the latest version as simple as a single command.
1. Why Docker?
- Isolation: n8n needs Node.js. If you install it directly on your server, it might conflict with other apps. Docker keeps it in its own "Box."
- Persistence: Using "Volumes," your workflows and credentials stay safe even if you delete the container.
2. The docker-compose.yml
Create a folder named n8n and save this as docker-compose.yml:
version: '3.8'
services:
n8n:
image: n8nio/n8n:latest
restart: always
ports:
- "5678:5678"
environment:
- N8N_HOST=localhost
- N8N_PORT=5678
- N8N_PROTOCOL=http
- NODE_ENV=production
- WEBHOOK_URL=http://localhost:5678/
volumes:
- ./n8n_data:/home/node/.n8n
3. Starting the Engine
Run this command in the same folder:
docker-compose up -d
You can now visit http://localhost:5678 in your browser.
4. Updates
Updating n8n is easy:
docker-compose pull(Downloads the new version).docker-compose up -d(Restarts with the new version). Your data inn8n_datais preserved!
Visualizing the Docker Setup
graph LR
Browser[Web Browser] -->|Port 5678| Docker[Docker Container]
Docker --> N8N[n8n Application]
Docker --> Vol[Volume Mount]
Vol -->|Persists| Data[./n8n_data<br/>Workflows & Credentials]
subgraph "Host Machine"
Data
end
subgraph "Container"
N8N
end
Exercise: The Container Launch
- Install Docker and Docker Compose on your machine (if not already there).
- Create the
docker-compose.ymlfrom Section 2. - Start n8n and login to the setup screen.
- Why did we use
./n8n_data:/home/node/.n8nin the volumes section? (Review Docker Module 3). - Research: What is the
N8N_ENCRYPTION_KEYand why should you back it up immediately?
Summary
You now have a private "Automation Factory" running on your machine. Docker makes the management of n8n predictable and scalable.
Next Lesson: Opening the doors: Setting up a Reverse Proxy (Nginx/Traefik).