# n8n 3.0: migrate from npm to Docker without losing workflows | Nuvits

Source: [https://nuvits.net/en/blog/migrate-n8n-npm-to-docker-n8n-3](https://nuvits.net/en/blog/migrate-n8n-npm-to-docker-n8n-3)

Published 2026-11-30, by Fernando Chagas.

Self-hosted n8n 3.0 requires Docker. If you run n8n with npm or `npx n8n`, migrate n8n from npm to Docker before you upgrade: the same version, the `~/.n8n` folder mounted at `/home/node/.n8n`, and the same encryption key. This guide makes that move, checks workflows, credentials and executions, and only then points the image tag at a 3.x release.

## What changes in n8n 3.0

The [v3.0 Breaking changes](https://docs.n8n.io/changelog/v30-breaking-changes) page draws the line: self-hosted n8n 3.0 requires a Docker-based deployment. Installations that use `npm` or `npx n8n` are no longer supported, and n8n 3.0 does not publish a runnable `n8n` package to npm. If you still use npm or npx, move to Docker before you upgrade. If you already run your own Docker Compose file, you do not need to switch methods. Kubernetes and Helm stay out of this particular move: the announcement [Introducing n8n 3.0](https://blog.n8n.io/introducing-n8n-v3/) says those deployments are not affected, partly because the new security features depend on a container setup.

The fast path in the docs, for a new instance, is:

```bash
curl -fsSL https://get.n8n.io | sh
```

The [One-line setup](https://docs.n8n.io/deploy/host-n8n/install-options/one-line-setup) guide describes what that command does: it checks Docker, creates a new `n8n` folder, writes the files and starts a new instance. It does not read the `~/.n8n` folder your npm install already uses. To keep workflows and credentials, use the Compose file in this guide and mount that folder.

For production, the same breaking-changes page points to [Install using Docker Compose](https://docs.n8n.io/deploy/host-n8n/install-options/install-using-docker-compose) with Postgres instead of the SQLite database bundled with n8n. That database change is a separate step, covered below. The first boot under Docker stays on the SQLite database you already have.

On 30 November 2026 the stable GitHub release was `n8n@2.49.9`, and the Docker Hub tags `stable` and `latest` pointed at that same image. The 3.x releases published by then, including `3.4.1`, were still marked pre-release, and the breaking-changes page still described `3.0.0` as an early access release. The announcement expected the stable 3.x in early December and said the move to 3.x is one way: going back means restoring the backup. Pin a fixed tag. `latest`, `stable`, `beta` and `next` move.

If `n8n --version` still starts with `1.`, the announcement is direct: there is no path from 1.x to 3.x. Upgrade to 2.x first. Support for 1.x ends on 31 December 2026.

From n8n 2.39 the editor has a report under Settings > Migration Report. The announcement recommends opening that report on the latest 2.x, fixing what it flags, and only then moving to 3.x. The report lists workflows and instance settings. The npm-to-Docker move is the other prerequisite, and it is what this guide covers.

## Stop the process and keep a backup

Write down the version while the process still answers. The output is the image tag, for example `2.49.9`:

```bash
n8n --version
```

Also read the variables it was started with. The number in the `pgrep` output is the PID:

```bash
pgrep -af '[n]8n'
sudo sh -c 'tr "\0" "\n" < /proc/PID/environ' | grep -E '^(N8N_|GENERIC_TIMEZONE|TZ|DB_)'
```

If n8n runs in a systemd unit, `systemctl cat UNIT_NAME` shows the unit's `Environment=` lines. Copy `N8N_ENCRYPTION_KEY`, `N8N_HOST`, `N8N_PROTOCOL`, `N8N_WEBHOOK_URL` or `WEBHOOK_URL`, `GENERIC_TIMEZONE`, `TZ` and any `DB_*` variable. That output contains the key when the key is set in the environment: do not paste it into a ticket.

Stop the process and remove it from startup. Two processes on the same SQLite file corrupt it, and both fight over port 5678.

Under pm2, use the name `pm2 list` shows:

```bash
pm2 list
pm2 stop NAME
pm2 delete NAME
pm2 save
```

Under systemd, use the name from the list:

```bash
systemctl list-units --type=service --all | grep -i n8n
sudo systemctl disable --now UNIT_NAME
```

Confirm that no process and no listener remain:

```bash
pgrep -af '[n]8n' || echo 'no n8n process'
ss -ltn | grep ':5678' || echo 'port 5678 is free'
```

The data folder is `~/.n8n` of the user who started n8n. If that user was `root`, the folder is `/root/.n8n`. If `N8N_USER_FOLDER` was set, the [backup](https://docs.n8n.io/deploy/host-n8n/keep-n8n-running/backup-and-restore) docs say n8n uses the `.n8n` subfolder of that path. The [Choose n8n's database](https://docs.n8n.io/deploy/host-n8n/configure-n8n/choose-n8ns-database) page puts SQLite at `~/.n8n/database.sqlite`. The `config` file in the same folder holds the key. Binary data in filesystem mode lives in that folder too, under `binaryData`. Community nodes installed on the instance live under `nodes`.

The same backup page says to stop n8n before copying the folder when the database is SQLite. Copying the file while n8n is writing to it can produce an inconsistent backup. With the process already stopped:

```bash
N8N_DIR=/home/deploy/.n8n
install -d -m 700 "$HOME/n8n-backup"
sudo tar czf "$HOME/n8n-backup/n8n-home-$(date +%F).tar.gz" -C "$(dirname "$N8N_DIR")" .n8n
sudo chown "$USER:" "$HOME/n8n-backup/n8n-home-$(date +%F).tar.gz"
tar tzf "$HOME/n8n-backup/n8n-home-$(date +%F).tar.gz" | grep -E '^\.n8n/(config|database\.sqlite)$'
```

Replace `/home/deploy/.n8n` with the real path. `grep` must print both `.n8n/config` and `.n8n/database.sqlite`. The rest of the folder, including `binaryData` and `nodes` when they exist, is in the same archive because `tar` stores the whole directory.

The key is the `encryptionKey` field of `config`:

```bash
sudo python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["encryptionKey"])' "$N8N_DIR/config"
```

If the process already had `N8N_ENCRYPTION_KEY`, use that value. It has to be identical to the file. When the two differ, n8n refuses to start and logs `Mismatching encryption keys`.

Copy the tar off the VPS, from your own machine, and store the key in a password manager:

```bash
mkdir -p backups-n8n
scp deploy@VPS_IP:n8n-backup/n8n-home-YYYY-MM-DD.tar.gz ./backups-n8n/
```

> **Without the key, the credentials cannot be opened.** n8n stores credentials encrypted. [Set a custom encryption key](https://docs.n8n.io/deploy/host-n8n/configure-n8n/basic-configuration/configuration-examples/set-a-custom-encryption-key) and the backup page say the same thing: without the key from `config`, or the same `N8N_ENCRYPTION_KEY`, a restored database opens and the workflows show up, but the credentials cannot be read.

If `DB_TYPE` was already `postgresdb`, the workflows are in that Postgres, not in `database.sqlite`. Dump that database as well, as in [Automatic n8n backups](https://nuvits.net/en/blog/n8n-automatic-backup). The `.n8n` folder stays in the backup because of the key. The Compose file below has to receive the same `DB_*` variables. Without them, n8n opens the SQLite file in the mounted folder and the instance looks empty.

## Start the same version with Docker Compose

The official image runs as the user `node`. On `n8nio/n8n:2.49.9` that is uid 1000 and gid 1000. The start commands below print the uid of the tag in `.env`. If they print another number, use that number in place of `1000`.

Create the project and write the `.env`. `N8N_VERSION` is the output of `n8n --version`, not `latest`. `N8N_ENCRYPTION_KEY` is the key from the previous step. `GENERIC_TIMEZONE` is the timezone the old process already used; the example is `America/Sao_Paulo`. `N8N_HOST`, `N8N_PROTOCOL` and `N8N_WEBHOOK_URL` are the values you copied from the process. [Configure webhook URLs with reverse proxy](https://docs.n8n.io/deploy/host-n8n/configure-n8n/basic-configuration/configuration-examples/configure-webhook-urls-with-reverse-proxy) explains the set: without a proxy, n8n builds the webhook URL from `N8N_PROTOCOL`, `N8N_HOST` and `N8N_PORT`. Behind a proxy, set `N8N_WEBHOOK_URL` and `N8N_PROXY_HOPS=1`. `N8N_WEBHOOK_URL` exists from 2.30.0. Before that the variable is called `WEBHOOK_URL`. From 2.35.0, `WEBHOOK_URL` is deprecated and n8n logs a warning if it is still set.

```ini
N8N_VERSION=2.49.9
N8N_ENCRYPTION_KEY=paste-the-key-from-config
GENERIC_TIMEZONE=America/Sao_Paulo
N8N_HOST=n8n.example.com
N8N_PROTOCOL=https
N8N_WEBHOOK_URL=https://n8n.example.com/
```

```bash
mkdir -p ~/n8n && cd ~/n8n
chmod 600 .env
```

The `2.49.9` in the example was the stable release when this was written. Replace it with your version. If the editor is only opened at `http://127.0.0.1:5678`, delete `N8N_HOST`, `N8N_PROTOCOL` and `N8N_WEBHOOK_URL` from `.env`, and delete those three variables plus the `N8N_PROXY_HOPS` line from the Compose file.

If `n8n --version` is older than 2.30.0, n8n ignores `N8N_WEBHOOK_URL`. In the `.env` and in the Compose file, the variable name is `WEBHOOK_URL`. From 2.30.0 on, keep `N8N_WEBHOOK_URL`.

```yaml
services:
  n8n:
    image: n8nio/n8n:${N8N_VERSION}
    restart: unless-stopped
    ports:
      - "127.0.0.1:5678:5678"
    environment:
      - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
      - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - TZ=${GENERIC_TIMEZONE}
      - N8N_HOST=${N8N_HOST}
      - N8N_PORT=5678
      - N8N_PROTOCOL=${N8N_PROTOCOL}
      - N8N_WEBHOOK_URL=${N8N_WEBHOOK_URL}
      - N8N_PROXY_HOPS=1
    volumes:
      - /home/deploy/.n8n:/home/node/.n8n
```

What this file does:

- The image is `n8nio/n8n` with a fixed tag, the same form as the official Compose file in `docker/get-n8n-compose.yml`. The [update](https://docs.n8n.io/deploy/host-n8n/keep-n8n-running/update-n8n) docs ask for a specific tag instead of `latest`.
- The volume binds the folder npm already used at `/home/node/.n8n`. The [Install with Docker](https://docs.n8n.io/deploy/host-n8n/install-options/install-with-docker) page documents that path. An empty named volume would start a new instance and generate another key.
- The port is bound to `127.0.0.1`. A reverse proxy on the VPS that already forwarded to port 5678 still reaches n8n. Publishing `5678:5678` opens the port on the internet, and Docker bypasses ufw, as in [Docker port still open with ufw](https://nuvits.net/en/blog/docker-port-still-open-with-ufw).
- `N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true` is what the official `docker run` example sets. When the folder is owned by uid 1000, n8n tightens `config` to mode `0600`.
- `restart: unless-stopped` brings the container back if the VPS reboots, and a manual `docker compose stop` stays stopped.
- This file does not set `DB_TYPE`. n8n's default is the SQLite file in the mounted folder. If the old process had `DB_TYPE=postgresdb`, add the same variables you copied to `environment`, with the same values:

```yaml
- DB_TYPE=${DB_TYPE}
- DB_POSTGRESDB_HOST=${DB_POSTGRESDB_HOST}
- DB_POSTGRESDB_PORT=${DB_POSTGRESDB_PORT}
- DB_POSTGRESDB_DATABASE=${DB_POSTGRESDB_DATABASE}
- DB_POSTGRESDB_USER=${DB_POSTGRESDB_USER}
- DB_POSTGRESDB_PASSWORD=${DB_POSTGRESDB_PASSWORD}
```

Inside the container, `localhost` and `127.0.0.1` are the container, not the VPS. If the old host was either of those, change `DB_POSTGRESDB_HOST` to `host.docker.internal` and add this to the service:

```yaml
extra_hosts:
  - "host.docker.internal:host-gateway"
```

`host-gateway` is the host address on the Docker network. Postgres has to accept connections on that address. If `ss -ltn | grep 5432` shows only `127.0.0.1`, the container cannot reach the database. The logs say the connection could not be established, and that editor is not the migrated instance.

Point the volume path at the same value as `N8N_DIR`. Compose does not expand `~` in this file: use an absolute path.

Give the folder to uid 1000 and start:

```bash
N8N_DIR=/home/deploy/.n8n
cd ~/n8n
sudo docker compose pull
sudo docker run --rm --entrypoint id "n8nio/n8n:$(grep ^N8N_VERSION= .env | cut -d= -f2-)"
sudo chown -R 1000:1000 "$N8N_DIR"
sudo docker compose up -d
sudo docker compose ps
ok=0
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
  if curl -fsS http://127.0.0.1:5678/healthz; then
    ok=1
    break
  fi
  sleep 2
done
test "$ok" -eq 1
sudo docker compose logs n8n
sudo docker compose exec -T n8n n8n --version
```

`id` must contain `uid=1000(node)`. `curl` retries for up to 30 seconds while n8n finishes its migrations, and `test` passes only when the response is `{"status":"ok"}`. The logs must contain the line `Editor is now accessible via:`. `--version` must print the same version as the earlier `n8n --version`.

If the logs show `EACCES: permission denied, open '/home/node/.n8n/crash.journal'` or `EPERM` while changing the permissions of `config`, the folder is still not owned by the `node` uid. Run `chown` again and `sudo docker compose up -d`. If you see `Mismatching encryption keys`, the value in `.env` differs from the file's `encryptionKey`. Fix `.env` and start again. Do not delete `config` to "fix" it: n8n would create another key.

## Check login, workflows and webhooks

Open the editor at the same address as before. Sign in with the same user. Check three things:

- The workflow list is the one you already had.
- A credential opens, without a warning that it could not be decrypted.
- Under Executions, the old history is still listed. It lives in the `database.sqlite` file you mounted.

On a workflow with a Webhook node, the production URL must use the public domain, with `https`, and without port `5678`. If the URL still shows `localhost:5678`, `N8N_WEBHOOK_URL` and `N8N_PROXY_HOPS` are missing, or the proxy is not sending `X-Forwarded-For`, `X-Forwarded-Host` and `X-Forwarded-Proto`. That internal URL is covered in [The n8n webhook shows localhost:5678](https://nuvits.net/en/blog/n8n-webhook-localhost-5678).

Leave the npm process stopped. Starting both at once points both at the same SQLite file.

## Change the tag to n8n 3.x

Do this step only after the Docker editor has been checked on the old version.

Take a snapshot of the VPS in the provider panel, in addition to the tar. 3.x runs database migrations when it starts. The update docs say that changing the tag back does not undo those migrations. The 3.0 announcement says going back means restoring the backup.

Before you change the tag, look at the binary-data directories. On first start, n8n 3.0 renames `~/.n8n/binaryData` to `~/.n8n/storage`. If both directories exist, it stops with an error instead of picking one. The breaking-changes page says to move the contents of `binaryData` into `storage` and remove `binaryData`. If only one of the two exists, leave it: n8n renames it itself.

```bash
if [ -d "$N8N_DIR/binaryData" ] && [ -d "$N8N_DIR/storage" ]; then
  sudo cp -a "$N8N_DIR/binaryData/." "$N8N_DIR/storage/"
  sudo rm -rf "$N8N_DIR/binaryData"
  sudo chown -R 1000:1000 "$N8N_DIR"
fi
```

Change `N8N_VERSION` in `.env` to the fixed 3.x tag you read in the [releases](https://github.com/n8n-io/n8n/releases). While 3.x is still marked pre-release, make that change on a copy of the instance, not on the one that receives production webhooks.

```bash
cd ~/n8n
sudo docker compose pull
sudo docker compose up -d
sudo docker compose logs -f n8n
```

`Ctrl+C` leaves the logs and leaves the container running. Check the login, a workflow, a credential and an execution again.

Two 3.0 effects show up on that boot, both on the breaking-changes page:

- Unverified community packages default to off. Ones already installed under `~/.n8n/nodes` stop loading unless you set `N8N_UNVERIFIED_PACKAGES_ENABLED=true`.
- Encryption key rotation turns on. Credentials saved before the upgrade stay readable. The docs give the usual instruction: back up the database first.

The rest of the breaking changes (removed nodes, Slack, the in-memory binary data mode) are in the Migration Report and on the breaking-changes page. This guide does not cover each one.

If you already run queue mode, repeat the same tag on the main instance, the workers and the runner. [n8n queue mode with Redis](https://nuvits.net/en/blog/configure-n8n-queue-mode-redis-vps) is that layout, and the update page requires the same version on every process.

## PostgreSQL as a separate step

The SQLite database that came from npm is still valid after the move to Docker. Postgres is a different change, on another day, on the same n8n version, after Docker has been checked.

The Docker Compose guide is explicit: when you point n8n at a new Postgres, existing SQLite data does not come along. That setup is a fresh instance, not an in-place migration. Setting `DB_TYPE=postgresdb` and starting creates an empty database. The workflows stay in `database.sqlite`, which n8n no longer opens.

The official tool for moving data from one database type to the other is the `export:entities` and `import:entities` pair, on [Use the command line](https://docs.n8n.io/deploy/host-n8n/configure-n8n/use-the-command-line). On 2.49.9, this command exports the running instance and writes `entities.zip`:

```bash
cd ~/n8n
sudo docker compose exec -T -u node n8n n8n export:entities --outputDir=/home/node/.n8n/entity-export
```

The command itself warns that the feature is still under development. The documented flag `--includeExecutionHistoryDataTables=true` includes the history tables, which are left out by default. Importing into an empty Postgres, with `--truncateTables`, is on the same page. Do it on a copy, read the whole output, and keep the same `N8N_ENCRYPTION_KEY` and the same `config`. The production Compose file with Postgres, Caddy and the runner is in [How to install n8n with Docker on a VPS](https://nuvits.net/en/blog/install-n8n-docker-vps).

## Roll back

While the image is still the old version, `docker compose down` stops the container and leaves `~/.n8n` on disk. The npm process can come back then, with the same user and the same key. Do not start both.

```bash
cd ~/n8n
sudo docker compose down
```

After 3.x has started and migrated the database, pointing the old tag at that folder does not undo the migration. Restore the VPS snapshot, or stop n8n and put the folder back from the tar you took before the tag change. The 3.0 announcement sums it up: going back means restoring the backup.

## Checklist

- `n8n --version` is written down, and the image uses that tag, not `latest`.
- The npm, pm2 or systemd process is stopped and out of startup. Port 5678 is free before Compose starts.
- A tar of `~/.n8n` was taken while n8n was stopped, contains `config` and `database.sqlite`, and has been copied off the VPS. The key is in a password manager.
- The folder is owned by uid 1000. `curl` to `/healthz` returns `{"status":"ok"}`. The version inside the container is the previous one.
- If the old process used Postgres, the Compose file has the same `DB_*` variables. `localhost` was changed to `host.docker.internal` when the database listened on the VPS, and the logs do not say the connection failed.
- Login, workflows, one credential and the execution history were checked before any 3.x tag.
- A VPS snapshot was taken before the 3.x tag. `N8N_WEBHOOK_URL` (or `WEBHOOK_URL` before 2.30.0), `N8N_HOST` and `N8N_PROXY_HOPS` match the old process. The proxy sends the three `X-Forwarded-*` headers.

## Next steps

- The production install with Postgres, an external runner and HTTPS is in [How to install n8n with Docker on a VPS](https://nuvits.net/en/blog/install-n8n-docker-vps).
- The daily backup, with the key inside the copy, is in [Automatic n8n backups](https://nuvits.net/en/blog/n8n-automatic-backup).
- For more than one worker, the next step is [n8n queue mode with Redis](https://nuvits.net/en/blog/configure-n8n-queue-mode-redis-vps). VPS size is in [How much RAM and vCPU for n8n, Evolution API and Coolify](https://nuvits.net/en/blog/how-much-ram-vcpu-n8n-evolution-api-coolify-vps).
- The VPS this n8n runs on is the [VPS for n8n](https://nuvits.net/en/n8n-vps).
