How to Self-Host n8n with Docker (Step by Step)
Self-host n8n with Docker: the run command, a Docker Compose setup with PostgreSQL, HTTPS, the env vars that matter, queue mode, updates and backups.

How Do You Self-Host n8n with Docker?
To self-host n8n with Docker, create a volume with docker volume create n8n_data, then run the official image n8nio/n8n with port 5678 published and the volume mounted at /home/node/.n8n. Open http://localhost:5678 and create the owner account. For a real server, use Docker Compose with PostgreSQL and put a reverse proxy with HTTPS in front.
That is the short version. The rest of this guide walks through each step in order: a quick local test, a Compose setup you can keep, HTTPS, the environment variables worth knowing, queue mode, and how to update without losing data.
n8n changes fast. Variable names and defaults can shift between major versions, so keep the official n8n hosting docs open next to this page and trust them where they differ.
What Do You Need Before You Install n8n?
You need a machine with Docker and the Docker Compose plugin. For a local test, Docker Desktop is enough. For a server, any Linux VPS works.
Our main n8n guide uses a small VPS with 2 vCPU and 4GB RAM as its baseline. That is plenty for a single instance running mostly API-call workflows. Start small. You can resize later.
- Docker and Docker Compose installed
- A domain or subdomain pointed at the server, if you want webhooks from outside
- Ports 80 and 443 open for the reverse proxy
- A place to store backups that is not the same server
How to Run n8n with a Single Docker Command
Use this to try n8n on your laptop. First create the volume: docker volume create n8n_data. Then start the container: docker run -it --rm --name n8n -p 5678:5678 -v n8n_data:/home/node/.n8n n8nio/n8n.
n8n listens on port 5678 by default. Open http://localhost:5678 and the setup screen asks you to create an owner account.
The volume matters. The folder /home/node/.n8n holds the SQLite database and the encryption key that protects your saved credentials. Skip the volume and you lose every workflow when the container stops.
To set your timezone, add -e GENERIC_TIMEZONE=Europe/Berlin -e TZ=Europe/Berlin with your own zone. GENERIC_TIMEZONE controls schedule nodes. TZ sets the system time inside the container.
This setup uses SQLite. That is fine for testing. Do not keep it for production. Our main guide calls this out as the one trap to avoid, and the fix is the next step.
How to Set Up n8n with Docker Compose and PostgreSQL
n8n's own docs recommend Docker Compose for a server install. Compose keeps the whole setup in one file you can commit to a private repo. Create a folder, add a .env file for secrets and a compose.yaml with two services: postgres and n8n.
The postgres service uses the official postgres image, a named volume for its data, and POSTGRES_USER, POSTGRES_PASSWORD and POSTGRES_DB read from the .env file. Add a healthcheck so n8n waits until the database is ready.
The n8n service uses the image n8nio/n8n, maps port 5678, mounts the n8n_data volume at /home/node/.n8n and sets the database variables listed below. Keep the volume even with PostgreSQL. n8n still stores its encryption key there unless you pass one yourself.
Start everything with docker compose up -d. Check the logs with docker compose logs -f n8n. When the log says the editor is accessible, open the URL and create the owner account.
Pin the image to a specific version tag instead of latest. You decide when to upgrade, and a restart never surprises you with a new major version.
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres (the Compose service name)
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_USER and DB_POSTGRESDB_PASSWORD, matching the postgres service
- N8N_ENCRYPTION_KEY set to a long random string you generate once and store safely
How to Put n8n Behind HTTPS and Fix Webhook URLs
Never expose port 5678 to the internet over plain HTTP. Put a reverse proxy in front. The official n8n Compose example uses Traefik, which also fetches TLS certificates for you. Caddy and Nginx work just as well. Use the one you already know.
Then tell n8n its public address. Set N8N_HOST to your domain, N8N_PROTOCOL to https and WEBHOOK_URL to the full public base URL, such as https://n8n.example.com/. Leave paths off the end. Newer releases also document an N8N_WEBHOOK_URL variable, so check the docs for the version you run.
This step fixes the most common self-hosting bug. Without it, n8n builds webhook URLs from its internal address, so Slack, Stripe or GitHub try to call localhost:5678 and nothing arrives.
Once the proxy works, remove the public port mapping from the n8n service. Only the proxy should reach it.
Which n8n Environment Variables Matter Most?
n8n has hundreds of settings. A handful decide whether your instance survives a restart, a migration or a bad day.
The encryption key is the one people lose. n8n encrypts stored credentials with it. If you move to a new server with a database dump and no key, every credential is unreadable and you re-enter them all by hand.
- N8N_ENCRYPTION_KEY — protects credentials. Set it yourself and back it up outside the server
- DB_TYPE and the DB_POSTGRESDB_ variables — point n8n at PostgreSQL
- N8N_HOST, N8N_PROTOCOL and WEBHOOK_URL — make webhook and OAuth callback URLs correct
- GENERIC_TIMEZONE and TZ — make schedules fire at the hour you meant
- EXECUTIONS_MODE — switches between regular and queue mode
- Execution data pruning settings — stop old execution logs from filling the disk
When Should You Enable n8n Queue Mode?
Queue mode splits n8n into a main process and one or more workers. The main process takes triggers and webhooks, pushes jobs to Redis, and workers execute them. Turn it on when one process can no longer keep up, or when a heavy workflow makes the editor slow.
You need three things: PostgreSQL, Redis and the same settings on every container. Set EXECUTIONS_MODE=queue on the main instance and on each worker. Point them at Redis with QUEUE_BULL_REDIS_HOST and QUEUE_BULL_REDIS_PORT. Start workers from the same image with the command worker.
Every worker must share the main instance's N8N_ENCRYPTION_KEY and reach the same database. A worker with a different key cannot decrypt credentials, and every job that needs one fails.
Do not start here. A single container with PostgreSQL carries most small teams a long way. Add queue mode when you see executions waiting, not before.
How Do You Update and Back Up Self-Hosted n8n?
Back up first, then update. With Compose, change the version tag, run docker compose pull, then docker compose down, then docker compose up -d. n8n runs its database migrations on start. With plain Docker, pull the new image, stop the container and start it again with the same volume.
Read the release notes before a major version jump. Breaking changes are listed there, and a rollback after a migration is harder than waiting a day.
Test the restore once. A backup you have never restored is a guess.
- Dump the database on a schedule with pg_dump and copy it off the server
- Store the encryption key in a password manager or secrets store
- Export workflows as JSON to a Git repository as a second copy
- Keep your compose.yaml and .env in a private repo or encrypted backup
Frequently Asked Questions
Is self-hosted n8n free?
The Community edition is free to self-host under n8n's Sustainable Use License, with no per-execution fee. You pay for the server and your own time. Some features, such as SSO, sit in paid plans.
What port does n8n use in Docker?
n8n listens on port 5678 by default. Publish it with -p 5678:5678 for local use. On a server, keep it private and let a reverse proxy on 443 forward traffic to it.
Which Docker image should I use for n8n?
Use the official image, n8nio/n8n. The same image is published on Docker Hub as n8nio/n8n. Pin a version tag in production so upgrades happen when you choose.
Does n8n need PostgreSQL?
No, it runs on SQLite out of the box. SQLite is fine for testing and light personal use. Use PostgreSQL for production, and you must use it for queue mode.
How much RAM does self-hosted n8n need?
It depends on your workflows. Small API-call workflows run on a modest VPS, and our main guide uses 2 vCPU and 4GB RAM as a comfortable baseline. Workflows that load large files or big datasets into memory need more.
Keep reading
All guides →
15 n8n Workflow Examples You Can Build Today
15 practical n8n workflows for alerts, data sync, AI, DevOps and content. Each one lists the trigger, the main nodes and the gotcha that bites first.

n8n AI Agent Tutorial: Build Your First Agent
Build your first n8n AI agent step by step: Chat Trigger, AI Agent node, chat model, memory and tools. Plus the limits and mistakes to know before you ship.

Selling n8n Workflow Templates: Where and What to Expect
Where to sell n8n workflow templates, what tends to sell, pricing models, what n8n's license allows, and why you should keep your income expectations modest.