How to Self-Host n8n with Docker and Docker Compose
Run n8n on your own server with the official Docker image: a quick docker run test, a Compose setup, HTTPS behind a reverse proxy, backups and updates.

Before you start
- A Linux server or local machine with Docker Engine and the Docker Compose plugin installed
- Comfort running commands in a terminal
- For production: a domain or subdomain you can point at the server
This guide takes you from a fresh server to a working, self-hosted n8n instance. You will start n8n with a single docker run command to confirm everything works, move to a Docker Compose file you can keep under version control, put n8n behind a reverse proxy with HTTPS for production use, and set up backups so your workflows and credentials survive a failed disk or a bad upgrade.
Before you start: what self-hosting involves
Self-hosting n8n gives you full control over where your workflows and data live, but you also take on the work a hosted service would do: updates, security, uptime and backups. n8n also offers a hosted cloud service if that trade-off does not suit you, and our comparison of Zapier, Make and n8n covers the wider choice.
n8n keeps its data in /home/node/.n8n inside the container, including a SQLite database (the default) with your workflows, credentials and execution history, plus the encryption key that protects stored credentials. The most important rule of self-hosting n8n is to keep that folder on persistent storage, which is why every example below uses a named Docker volume.
Step 1: Test n8n with docker run
Create a named volume, then start a temporary container from the official image. Replace Europe/London with your own time zone name, such as America/New_York.
docker volume create n8n_data
docker run -it --rm \
--name n8n \
-p 5678:5678 \
-e GENERIC_TIMEZONE="Europe/London" \
-e TZ="Europe/London" \
-v n8n_data:/home/node/.n8n \
docker.n8n.io/n8nio/n8nOpen http://localhost:5678 in a browser and create the owner account. GENERIC_TIMEZONE sets the time zone n8n uses for scheduled workflows, while TZ sets the system time zone inside the container. Setting both avoids schedules that run hours early or late.
Step 2: Move to Docker Compose
For an instance you plan to keep running, a Compose file is easier to maintain than a long command. Create a directory such as ~/n8n and add a compose.yaml file:
services:
n8n:
image: docker.n8n.io/n8nio/n8n
restart: unless-stopped
ports:
- "127.0.0.1:5678:5678"
environment:
- GENERIC_TIMEZONE=Europe/London
- TZ=Europe/London
volumes:
- n8n_data:/home/node/.n8n
volumes:
n8n_data:
external: trueexternal: true tells Compose to reuse the n8n_data volume you created in Step 1, so anything you set up during the test carries over. If you skipped Step 1, run docker volume create n8n_data first. Binding the port to 127.0.0.1 means n8n is reachable only from the server itself; the reverse proxy in Step 3 will handle public traffic. Start the stack and follow the logs:
cd ~/n8n
docker compose up -d
docker compose logs -f n8nStep 3: Add a reverse proxy with HTTPS
Do not expose port 5678 directly to the internet. Put a reverse proxy in front of n8n to handle HTTPS. Caddy is a straightforward option because it obtains and renews TLS certificates automatically; Nginx and Traefik work too. Point a DNS record such as n8n.example.com at your server, install Caddy on the host, and use a Caddyfile like this:
n8n.example.com {
reverse_proxy localhost:5678
}Then tell n8n its public address so it generates correct webhook URLs. Add these lines to the environment section of your Compose file and run docker compose up -d again:
- N8N_HOST=n8n.example.com
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://n8n.example.com/Finally, configure your firewall to allow only SSH and ports 80 and 443.
Step 4: Back up your data
Back up the whole volume, not just your workflows. It contains the encryption key: without it, credentials in a restored database cannot be decrypted. Stop n8n briefly so the database is not written to mid-backup, archive the volume with a throwaway container, then start n8n again:
docker compose stop n8n
docker run --rm \
-v n8n_data:/data:ro \
-v "$(pwd)":/backup \
alpine tar czf /backup/n8n-backup-$(date +%F).tar.gz -C /data .
docker compose start n8nCopy the archive off the server, because a backup on the same disk does not protect you from losing that disk. Schedule the job with cron and test a restore on another machine from time to time. For a portable, readable copy of your workflows, n8n's command-line interface can also export them as JSON:
docker compose exec n8n n8n export:workflow --all --output=/home/node/.n8n/workflows-backup.json
docker compose cp n8n:/home/node/.n8n/workflows-backup.json ./Step 5: Update and secure your instance
- Read the release notes for breaking changes, especially across major versions.
- Take a backup as described above.
- Pull the new image and recreate the container with
docker compose pullfollowed bydocker compose up -d. - Check the logs and run a few critical workflows to confirm they still behave as expected.
Beyond updates, use a strong owner password and two-factor authentication, keep the host operating system and Docker patched, and store API keys only in n8n's credentials system rather than in Code nodes or workflow notes. If your team works from known locations, restricting access to the editor with a VPN or IP allow-list adds another layer.
Troubleshooting
- Permission denied errors on startup. Usually caused by mounting a host directory instead of a named volume. The container runs as the
nodeuser (UID 1000), so a bind-mounted directory must be writable by that user. - A secure cookie warning when opening the editor over plain HTTP. n8n expects HTTPS when accessed from anywhere other than localhost. Set up the reverse proxy from Step 3;
N8N_SECURE_COOKIE=falseexists but is only appropriate for local testing. - Webhook URLs show localhost instead of your domain. Set
WEBHOOK_URLand recreate the container. - Schedules run at the wrong time. Check
GENERIC_TIMEZONEandTZ, and the time zone in each workflow's settings. - Workflows disappeared after recreating the container. The volume was not mounted at
/home/node/.n8n, or a different volume was used. Rundocker volume lsand check the mount in your Compose file.
Once n8n is running, browse our automation ideas for workflows to build first, or read our n8n profile for an overview of its features.
- #n8n
- #Docker
- #Self-hosting
- #Automation
- #DevOps
WebAIAutomation Editorial Team
Editors
Our editors test AI tools hands-on, document real workflows and keep every guide focused on practical, verifiable advice.
More guides

How to Use GitHub Copilot in VS Code: A Beginner's Guide
Set up GitHub Copilot in VS Code, accept inline suggestions, use chat, give better context, review the output carefully and adjust your privacy settings.

How to Write Effective AI Prompts: A Practical Framework
Learn a repeatable prompt structure (role, context, task, format and constraints) plus a simple iteration loop for getting useful answers from AI tools.

How to Automate Email Follow-Ups with Zapier and AI
Build a Zapier workflow that sends a personalized follow-up email when a form is submitted or a row is added, with an optional AI step to draft the text.
Newsletter
Stay ahead of AI and automation
A concise weekly brief with new tools worth trying, practical workflows and the technology shifts that matter.