How to install n8n with Docker (and when to use npm)
Otomatzia editorial team · Last verified
Short answer
For a local n8n Docker install, run the single-container command below and open http://127.0.0.1:45768. Use the downloadable Docker Compose file to test Postgres and persistence. Both examples were verified with n8n 2.49.7. New to the tool? Start with what n8n is.
| Topic | Detail |
|---|---|
| Recommended method | Docker for most self-hosting needs (n8n docs) |
| Official installer | See the n8n installer documentation for the complete stack. |
| Image and port | n8nio/n8n on port 5678 (n8n docs) |
| Data location | Volume mounted at /home/node/.n8n (n8n docs) |
| Default database | SQLite; Postgres advised for production (n8n docs) |
| npm | n8n 3.0 and later is not published to npm (n8n docs) |
| Versions when checked | Stable 3.4.4, beta 3.5.3 (n8n docs) |
Which Docker install method should you use?
n8n's docs recommend Docker for most self-hosting needs, because it gives a clean, isolated environment, avoids operating system and tooling incompatibilities, and makes database and environment management simpler, per the Docker install page. There are three Docker routes in the current docs, and they suit different jobs.
Before you pick one, be honest about the work. n8n's own guidance says self-hosting is for expert users and that mistakes can lead to data loss, security issues and downtime. If nobody on the team wants to run a server, our n8n Cloud vs self-hosted comparison covers the hosted option.
| Method | Best for | What you write | Source |
|---|---|---|---|
| One-line setup | A fresh install, fastest start | Nothing; the script writes compose.yml and .env | n8n docs |
| docker run | A quick single container test | One docker run command | n8n docs |
| Docker Compose by hand | Production setups that need Postgres | compose.yml, .env and a SearXNG settings file | n8n docs |
| npm (not Docker) | An existing 2.x install only | npm install n8n -g | n8n docs |
Where is the official Docker installer?
n8n documents an installer that sets up a complete stack. The single-container and Postgres examples below cover a local test where the editor is available only on your computer.
How do you run n8n with a single docker run command?
The Docker install page still publishes a plain docker run command, though it now marks that page as outdated and points to Docker Compose as the recommended method. It is still the clearest way to see what n8n needs: one image, one port and one volume. Replace the timezone placeholders with a value such as Asia/Jerusalem or America/New_York.
The command creates a volume for persistent data, downloads the n8nio/n8n image, maps port 5678, sets TZ for the system clock and GENERIC_TIMEZONE for schedule nodes such as the Schedule Trigger, enforces secure permissions on the settings file, and mounts the n8n_data volume at /home/node/.n8n. The --rm flag removes the container when it stops; your data survives because it lives in the volume.
With this example, open http://127.0.0.1:45768. The /healthz route returned status ok in a loopback test.
docker volume create n8n_data
docker run -it --rm \
--name n8n \
-p 127.0.0.1:45768:5678 \
-e GENERIC_TIMEZONE="<YOUR_TIMEZONE>" \
-e TZ="<YOUR_TIMEZONE>" \
-e N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true \
-v n8n_data:/home/node/.n8n \
n8nio/n8n:2.49.7How do you test n8n and Postgres with Docker Compose?
Download the loopback Compose example. It uses n8n 2.49.7 and Postgres 17, with separate Docker volumes. Set N8N_FIXTURE_PG_PASSWORD to a strong local password in your shell before starting it.
We checked that n8n created its workflow table in Postgres and returned to readiness after restarting the n8n container. For a production deployment, follow the n8n Docker Compose guide. Back up the /home/node/.n8n volume and preserve your encryption key.
- From the folder containing the file, run docker compose -f compose-loopback.yaml up --wait.
- Open http://127.0.0.1:45770/healthz/readiness and look for status ok.
- Stop and start n8n again with docker compose -f compose-loopback.yaml restart n8n. Check the same readiness URL once it has restarted.
When should you use npm instead of Docker?
Almost never for a new install. The npm install page says n8n 3.0 and later is not published to npm, and the n8n package there stays on the last 2.x release. The one-line setup guide adds that npm install n8n and npx n8n no longer work for new n8n 3.0 installs, and that existing npm installs keep working for now.
If you do run the 2.x package, it needs Node.js between 20.19 and 24.x, and n8n Assistant is not available with the npm method. Commands like export:workflow still work in both cases; under Docker you run them inside the container with docker exec, per the CLI docs.
Failure modes and fixes
Each row is a problem described in the n8n or Docker documentation, with the fix it gives.
| Symptom | Cause | Fix | Source |
|---|---|---|---|
| Workflows gone after removing the container | No volume; a container's writable layer is deleted with it | Mount a volume at /home/node/.n8n, as in the docker run command | Docker docs |
| All data deleted after a stop | docker compose down -v removes the volumes | Stop with down, without -v | n8n docs |
| Schedules fire at the wrong hour | GENERIC_TIMEZONE not set | Set GENERIC_TIMEZONE and TZ to your zone | n8n docs |
| Slow start or permission errors on Windows | Project folder under /mnt/c in WSL | Keep the folder inside the WSL filesystem, for example ~/n8n | n8n docs |
| Postgres starts with an empty database | PGDATA line removed for postgres:18 | Keep PGDATA set to /var/lib/postgresql/data | n8n docs |
| database files are incompatible with server | Image bumped to Postgres 18 over older data | Back up with pg_dumpall, then follow the Postgres upgrade guide | n8n docs |
| npm installs an old version | n8n 3.0 and later is not on npm | Use the one-line setup or Docker Compose | n8n docs |
Questions about n8n and Docker
Answers from the n8n and Docker documentation.
Can you host n8n on Docker?
Yes, and it is the recommended way. n8n's docs recommend Docker for most self-hosting needs, and from n8n 3.0 n8n is only distributed through Docker, per the one-line setup guide. The single-container example above is a tested local starting point.
Is Docker just a VM?
No. Docker's docs explain that a virtual machine boots its own complete operating system, kernel included, while a container is an isolated process that shares the host's kernel. That is why a container starts in about a second. The trade-off is that a VM's isolation is stronger. On macOS and Windows, Docker Desktop runs Linux containers inside a small Linux VM it manages for you.
How do I update n8n in Docker?
With Compose, run docker compose pull, then docker compose down, then docker compose up -d in the folder with your compose file. With a single container, pull n8nio/n8n, stop and remove the old container, and start a new one, per the Docker install page. One-line installs use the --upgrade flag.
Is the n8n tunnel safe for production?
No. The Docker install page says the cloudflared tunnel is for local development and testing and is not safe to use in production.
Want n8n installed and maintained for you
If you would rather not run the server yourself, describe your setup and we will point you to a fitting provider from the n8n provider list. You can also compare other tools in our n8n alternatives guide or on the n8n profile.
Sources
- n8n docs: host n8n (checked on )
- n8n docs: one-line setup (checked on )
- n8n docs: install with Docker (checked on )
- n8n docs: install using Docker Compose (checked on )
- n8n docs: install with npm (checked on )
- n8n docs: use the command line (checked on )
- Docker docs: what is a container? (checked on )
Vendor features and prices change. Confirm details on the linked official pages before you rely on them.
Keep reading
- What is n8n? A plain-English guide for business teams
- Gumloop vs n8n: credits, self-hosting and who should pick which
- n8n alternatives: who should switch and what to pick in 2026
- n8n Cloud vs self-hosted: which one to choose in 2026
- n8n Git: version control for workflows, paid and free routes
- n8n MCP server guide: connect Claude to your workflows