How to Deploy n8n with Docker: A Step‑by‑Step Guide
If you’ve been playing around with workflow automation, you’ve probably heard of n8n. It’s a powerful, open‑source tool that lets you stitch together APIs, databases, and services without writing a single line of code. The catch? Running it on your own machine can become a juggling act of dependencies, environment variables, and occasional version clashes.
Enter Docker. By containerising n8n, you lock in the exact runtime it needs, and you can spin the whole stack up (or shut it down) with a single command. Below is a pragmatic walk‑through that assumes you have basic familiarity with Docker but not necessarily a PhD in container orchestration.
Why Use Docker for n8n?
- Isolation: Your n8n instance lives in its own sandbox, untouched by other services.
- Portability: Move the container from a laptop to a cloud VM without tweaking configs.
- Reproducibility: The same image runs the same way every time, which makes debugging a lot easier.
All of that translates into less downtime when you need to upgrade or migrate.
Prerequisites
Before diving in, make sure you have:
- Docker Engine (or Docker Desktop) installed and running.
- A docker‑compose binary if you plan to orchestrate multiple services.
- Basic knowledge of terminal commands.
If any of these are missing, the official Docker site has quick installers for Windows, macOS, and Linux.
Step 1: Pull the Official n8n Image
The n8n team maintains an up‑to‑date image on Docker Hub. Pull it with:
docker pull n8nio/n8n:latestThat one‑liner fetches the most recent stable release. You can verify the download by running docker images and spotting n8nio/n8n in the list.
Step 2: Create a Persistent Data Volume
n8n stores workflow definitions, credentials, and execution logs on disk. To prevent data loss when the container stops, map a host directory to /home/node/.n8n inside the container.
mkdir -p $HOME/n8n-dataThis folder will survive container restarts, upgrades, or even complete deletions.
Step 3: Draft a Simple docker-compose.yml
While you could launch n8n with a solitary docker run command, a Compose file makes future tweaks friendlier. Save the following as docker-compose.yml in the same directory as your data folder:
version: '3.8'services:
n8n:
image: n8nio/n8n:latest
restart: unless-stopped
ports:
- "5678:5678"
environment:
- DB_TYPE=sqlite
- DB_SQLITE_VOLUMENAME=/home/node/.n8n/database.sqlite
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=admin
- N8N_BASIC_AUTH_PASSWORD=changeme
volumes:
- $HOME/n8n-data:/home/node/.n8n
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5678/healthz"]
interval: 30s
timeout: 10s
retries: 3
Key points to notice:
- The
portsmapping publishes n8n’s default UI port (5678) to your host. - We enable a minimal SQLite database for a quick start. If you need PostgreSQL or MySQL, swap the
DB_TYPEand add the appropriate connection strings. - Basic authentication is turned on; replace
adminandchangemewith strong credentials.
Step 4: Spin Up the Stack
From the directory containing docker-compose.yml, run:
docker-compose up -dThe -d flag detaches the process, letting the containers run in the background. Docker will download any missing layers, create the volume, and start the service. You can check the status with:
docker-compose psIf the health check passes, the STATUS column should read “Up (healthy)”.
Step 5: Access the n8n UI
Open a web browser and head to http://localhost:5678. You’ll be greeted by a login prompt (thanks to the basic auth we set). After authenticating, you land on the n8n editor where you can start dragging nodes, connecting APIs, and testing workflows.
Optional: Enable HTTPS with a Reverse Proxy
Running directly on http://localhost is fine for development, but production environments typically demand TLS. The most common pattern is to place an Nginx (or Traefik) container in front of n8n.
Here’s a minimalist Nginx snippet you could add to a separate service in the same docker-compose.yml:
nginx:image: nginx:alpine
restart: unless-stopped
ports:
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
- ./certs:/etc/ssl/certs:ro
depends_on:
- n8n
The accompanying nginx.conf would terminate SSL and proxy traffic to n8n:5678. Remember to obtain certificates from Let’s Encrypt or a trusted CA.
Troubleshooting Common Hiccups
- Port already in use: Change the host side of the mapping (e.g.,
"8080:5678") or stop the conflicting service. - Database lock errors: SQLite isn’t ideal for heavy concurrent writes. Switch to PostgreSQL if you anticipate high load.
- Container keeps restarting: Inspect logs with
docker-compose logs n8n. Missing environment variables or file‑permission issues surface quickly.
Keeping n8n Up‑to‑Date
When a new n8n version drops, you don’t need to rebuild anything from scratch. Simply pull the fresh image and restart:
docker-compose pulldocker-compose up -d
Docker will replace the old container while preserving your persistent volume, so workflows remain intact.
Wrapping Up
Containerising n8n with Docker eliminates most of the “works on my machine” headaches and gives you a clean, repeatable deployment pipeline. Whether you’re tinkering on a personal laptop or provisioning a production server, the steps above should get you up and running in under ten minutes.