Running n8n yourself costs nothing but a little setup. With Docker Compose you describe the whole setup in one file, so starting, stopping, backing up and updating n8n each take a single command. This is the setup the workflows on this site are built and tested on.
At the end of this guide you have:
- n8n running at
http://localhost:5678, reachable only from your own computer; - a fixed n8n version, so nothing changes until you decide to update;
- your workflows and credentials in a Docker volume that survives restarts and updates;
- a backup that you know how to restore.
What you need
- Docker with Docker Compose. On a Mac, Docker Desktop or OrbStack; on Linux, Docker Engine with the Compose plugin. Check it with
docker compose version. - A terminal. The commands in this guide are for macOS and Linux.
- About ten minutes.
Step 1: Create a folder and an encryption key
mkdir n8n && cd n8n
echo "N8N_ENCRYPTION_KEY=$(openssl rand -hex 32)" > .env
n8n encrypts the credentials you save (API keys, passwords) with this key. Keep the .env file safe and never change the key afterwards: with a different key, n8n can no longer read the credentials you already saved. If you keep this folder in git, add .env to your .gitignore.
Step 2: Write docker-compose.yml
Create a file called docker-compose.yml in the same folder:
services:
n8n:
image: docker.n8n.io/n8nio/n8n:2.45.7
container_name: n8n
restart: unless-stopped
ports:
- "127.0.0.1:5678:5678"
environment:
- N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY:?Set N8N_ENCRYPTION_KEY in .env}
- N8N_WEBHOOK_URL=http://localhost:5678/
- GENERIC_TIMEZONE=Europe/Amsterdam
- TZ=Europe/Amsterdam
- N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
volumes:
- n8n_data:/home/node/.n8n
volumes:
n8n_data:
name: n8n_data
What each part does:
imagepins n8n to one version. Avoidlatest: then every pull can bring a new version without you noticing. Check the n8n release notes for the current version.portswith127.0.0.1makes n8n reachable only from your own computer. Without it, anyone on your network can open it.N8N_ENCRYPTION_KEYcomes from.env. The:?makes Docker Compose stop with a clear error when the key is missing.N8N_WEBHOOK_URLis the address n8n shows in Webhook nodes. Since n8n 2, this replaces the oldWEBHOOK_URLvariable.GENERIC_TIMEZONEandTZset the time zone for schedules and logs. Change them to your own, for exampleAmerica/New_York.N8N_ENFORCE_SETTINGS_FILE_PERMISSIONSmakes sure only n8n can read its settings file.volumesstores everything n8n saves, including the database with your workflows, in a volume calledn8n_data. The fixed name keeps the backup commands below simple.
Step 3: Start n8n
docker compose up -d
docker compose logs -f n8n
Wait until the log shows n8n ready on ::, port 5678, then press Ctrl+C. That only stops following the log; n8n keeps running. Check that it responds:
curl http://localhost:5678/healthz
The answer is {"status":"ok"}. Now open http://localhost:5678 in your browser and create the owner account.
Step 4: Stop and start n8n
docker compose stop # stop n8n, keep everything
docker compose start # start it again
docker compose down # remove the container; your data stays in the volume
Never add -v to docker compose down unless you want to start over: docker compose down -v deletes the volume and every workflow in it.
Step 5: Make a backup
Stop n8n first, so the database is not written to while you copy it:
docker compose stop
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
This puts a file like n8n-backup-2026-11-01.tar.gz in your folder. Keep a copy of .env next to it: a backup without the encryption key cannot read its credentials.
Step 6: Restore a backup
docker compose down
docker run --rm -v n8n_data:/data alpine sh -c 'find /data -mindepth 1 -delete'
docker run --rm -v n8n_data:/data -v "$PWD":/backup alpine \
tar xzf /backup/n8n-backup-2026-11-01.tar.gz -C /data
docker compose up -d
The second command empties the volume, the third puts the backup back. Use the file name of your own backup, and the same .env as when you made it.
Step 7: Update n8n
- Make a backup (step 5).
- Change the version in
image:to the new one. - Pull the new image and restart:
docker compose pull
docker compose up -d
On the first start of a new version, n8n updates its database by itself. Read the release notes before a big jump in versions.
Common errors
required variable N8N_ENCRYPTION_KEY is missing a value: Set N8N_ENCRYPTION_KEY in .env
Docker Compose cannot find the key. Run the command from the folder that contains .env, and check that the file contains the line N8N_ENCRYPTION_KEY=....
Bind for 127.0.0.1:5678 failed: port is already allocated
Something else already uses port 5678, often another n8n. Stop that one, or change the first number in ports, for example to "127.0.0.1:5679:5678", and open http://localhost:5679.
Failed to start Python task runner in internal mode. because Python 3 is missing from this system.
You can ignore this unless you want to write Python in the Code node. JavaScript in the Code node works as usual.
WEBHOOK_URL -> Use N8N_WEBHOOK_URL instead
You are using the old variable name. Rename it to N8N_WEBHOOK_URL.
What’s next
Your n8n now runs only on your own computer. To receive webhooks from outside services such as a payment provider or a webshop, n8n needs an address on the internet; that gets its own guide. Rather not look after updates and backups yourself? n8n also offers n8n Cloud, hosted by n8n.