# How to Run n8n with Docker (2026 Setup Guide)

> Run docker volume create n8n_data, then start the official n8nio/n8n image with port 5678 published and the volume mounted at /home/node/.n8n. Open http://localhost:5678. That single container is fine for local use; for a server, n8n now recommends its Docker Compose setup, which needs Docker Compose v2, 4 GB RAM and 2 vCPUs.

Source page: https://aiwiserank.com/guides/n8n-docker · Last checked: 2026-10-27 · Tool: n8n

## Before you start

- **Docker installed.** Docker Desktop on Mac or Windows, or Docker Engine on Linux. Check with `docker --version`.
- **On Windows, use WSL 2.** Keep your n8n folder inside the Linux filesystem (for example `~/n8n`), not under `/mnt/c/...`. n8n's docs warn that mounting files across that boundary causes slow performance and permission errors.
- **Choose the setup:**
  - **Quick start (one container):** for trying n8n on your own machine.
  - **Docker Compose:** the setup n8n recommends for anything that runs long-term or on a server.

## Option 1: Quick start with one container

Create a volume so your workflows and credentials survive restarts, then start n8n:

```shell
docker volume create n8n_data

docker run -it --rm \
  --name n8n \
  -p 5678:5678 \
  -e GENERIC_TIMEZONE="Europe/London" \
  -e TZ="Europe/London" \
  -e N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true \
  -v n8n_data:/home/node/.n8n \
  n8nio/n8n
```

Open **http://localhost:5678** and create the owner account.

What each part does:

| Setting | Why it matters |
|---|---|
| `-p 5678:5678` | n8n's web interface and webhooks listen on port 5678. |
| `-v n8n_data:/home/node/.n8n` | Keeps workflows, credentials and the **encryption key** in the `n8n_data` volume. Without it, everything is lost when the container stops. |
| `GENERIC_TIMEZONE`, `TZ` | Sets the timezone used by schedule triggers and dates. Use a name from the [tz database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones), such as `America/New_York`. |
| `--rm` | Removes the container when it stops. Your data is safe in the volume. |

To keep n8n running in the background, replace `-it --rm` with `-d --restart unless-stopped`.

## Option 2: The recommended Docker Compose setup

n8n's current Compose setup runs n8n alongside a **sandbox service** for running code safely, plus a small web-search service. It needs:

- **Docker Compose v2.** Check with `docker compose version`.
- **At least 4 GB of RAM and 2 vCPUs.** The sandbox uses Docker-in-Docker, so a minimal server is too small.

The steps:

1. **Make a folder** for the project, for example `~/n8n`.
2. **Get the official `compose.yml`.** It's linked from n8n's [Docker Compose install page](https://docs.n8n.io/deploy/host-n8n/install-options/install-using-docker-compose/). Use that file rather than a copy from a blog, since its services change between releases.
3. **Create a `.env` file** with the variables the install page lists:
   - the n8n and sandbox **version numbers** (pin them to the latest stable releases);
   - **secrets** for the runner and the sandbox API. Generate a unique random value for each, for example with `openssl rand -hex 32`.
4. **Start it:**

   ```shell
   docker compose up -d
   docker compose ps
   ```

   Wait until the `sandbox-api` service shows **healthy**; the other services start after it.
5. **Check it's up:**

   ```shell
   curl -sf http://localhost:5678/healthz
   ```

**Security notes from n8n's checklist:**
- **The sandbox runner is privileged.** It uses Docker-in-Docker, so never expose it to the internet. Only n8n's port should be open on your firewall.
- **Rotate the sandbox secrets now and then,** and keep each one unique.

## Use PostgreSQL instead of SQLite

By default n8n stores data in SQLite inside `/home/node/.n8n`. For production, n8n recommends PostgreSQL. Its [n8n-hosting repository](https://github.com/n8n-io/n8n-hosting) has a ready-made Compose example with Postgres. The settings n8n reads are:

```shell
DB_TYPE=postgresdb
DB_POSTGRESDB_HOST=postgres
DB_POSTGRESDB_PORT=5432
DB_POSTGRESDB_DATABASE=n8n
DB_POSTGRESDB_USER=n8n
DB_POSTGRESDB_PASSWORD=change-me
DB_POSTGRESDB_SCHEMA=public
```

Two things to know:
- **Keep the `/home/node/.n8n` volume even with Postgres.** It still holds the encryption key, instance logs and source-control files. If you lose the encryption key, n8n can't decrypt your saved credentials.
- **Set `PGDATA` on Postgres 18.** It changed its default data location, so setting `PGDATA` keeps data where earlier versions put it. Upgrading Postgres to a new major version by changing the image tag fails; back up with `pg_dumpall` first and follow PostgreSQL's upgrade steps.

## Update n8n

**Single container:** pull the new image, then stop and start your container again with the same `docker run` command:

```shell
docker pull n8nio/n8n
```

**Docker Compose:** update the version in `.env` if you pinned one, then:

```shell
docker compose pull
docker compose down
docker compose up -d
```

Back up your volume (or database) before upgrading across major versions.

## Common problems

- **Workflows disappeared after a restart.** The container ran without the `-v n8n_data:/home/node/.n8n` volume. Add it; data from a container that has already been removed can't be recovered.
- **"Credentials could not be decrypted".** The encryption key in `/home/node/.n8n` changed or was lost. Always reuse the same volume.
- **Schedule triggers fire at the wrong hour.** Set `GENERIC_TIMEZONE` and `TZ`.
- **Webhooks don't work from outside your network.** On a server, put n8n behind a reverse proxy with HTTPS and a domain. n8n's built-in tunnel option is for local testing only, and its docs say it isn't safe for production.

## Sources

- https://docs.n8n.io/hosting/installation/docker/
- https://docs.n8n.io/deploy/host-n8n/install-options/install-using-docker-compose/
- https://github.com/n8n-io/n8n-hosting
