Nokto

Install n8n with Docker: locally, with docker compose, then in production

By Abdellah El KharrazePublished 6 min read

In short

To try n8n locally, one command is enough: docker run -it --rm -p 5678:5678 -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n, then open http://localhost:5678. For production, use docker compose with PostgreSQL, a fixed encryption key, an HTTPS reverse proxy, WEBHOOK_URL set and a pinned image version.

Key takeaways

  • Locally, a Docker volume on /home/node/.n8n is enough to keep your workflows between restarts.
  • In production, set N8N_ENCRYPTION_KEY and back it up: without it, your saved credentials become unreadable.
  • Behind a reverse proxy, WEBHOOK_URL must contain the public URL, otherwise n8n shows webhooks on localhost.
  • Pin the image version and update deliberately, never with a latest tag that changes under your feet.

Docker is the simplest, cleanest way to install n8n, whether to try it on your computer or to run it in production on a VPS. This guide starts from the shortest command and works up to a production setup: PostgreSQL, HTTPS, essential variables, updates and monitoring.

Step 0: prerequisites

  • Docker installed (Docker Desktop on Mac or Windows, Docker Engine on Linux) and, for what follows, Docker Compose (included in recent versions as docker compose).
  • For production: a Linux VPS (Ubuntu or Debian), a domain name pointing to its IP address, and ports 80 and 443 open.

Step 1: n8n locally in one command

To discover n8n on your machine:

docker volume create n8n_data

docker run -it --rm --name n8n \
  -p 5678:5678 \
  -v n8n_data:/home/node/.n8n \
  docker.n8n.io/n8nio/n8n

Open http://localhost:5678, create the owner account, and you are in the editor. The n8n_data volume keeps your workflows, credentials and the encryption key generated on first launch: you can stop and restart the container without losing anything.

This setup uses SQLite and is only reachable from your computer. Webhooks will not receive anything from the outside. It is perfect for learning, not for production.

Receiving webhooks locally

To test a webhook called by an external service, you need to expose your local n8n temporarily. Tunnel tools (Cloudflare Tunnel, ngrok…) give you a public URL that forwards to localhost:5678. Set that URL in WEBHOOK_URL when starting the container so n8n displays the right addresses.

Step 2: docker compose with PostgreSQL

For a lasting setup, you describe the services in a compose.yml file. Here is a commented baseline with PostgreSQL:

# compose.yml
services:
  postgres:
    image: postgres:16
    restart: unless-stopped
    environment:
      POSTGRES_USER: n8n
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: n8n
    volumes:
      - pg_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U n8n"]
      interval: 10s
      retries: 5

  n8n:
    image: docker.n8n.io/n8nio/n8n:2.44.0   # pinned version
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      DB_TYPE: postgresdb
      DB_POSTGRESDB_HOST: postgres
      DB_POSTGRESDB_DATABASE: n8n
      DB_POSTGRESDB_USER: n8n
      DB_POSTGRESDB_PASSWORD: ${POSTGRES_PASSWORD}
      N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
      N8N_HOST: n8n.example.com
      N8N_PROTOCOL: https
      WEBHOOK_URL: https://n8n.example.com/
      N8N_PROXY_HOPS: 1
      GENERIC_TIMEZONE: America/New_York   # or Europe/London
      TZ: America/New_York
      EXECUTIONS_DATA_PRUNE: "true"
      EXECUTIONS_DATA_MAX_AGE: 720      # hours: 30 days of history
    ports:
      - "127.0.0.1:5678:5678"           # listens locally only, the proxy does the rest
    volumes:
      - n8n_data:/home/node/.n8n

volumes:
  pg_data:
  n8n_data:

And a .env file next to it, never committed:

POSTGRES_PASSWORD=a-long-random-password
N8N_ENCRYPTION_KEY=a-long-random-key-to-back-up

Start with docker compose up -d, follow the logs with docker compose logs -f n8n.

The version number in the example is illustrative: replace it with the latest stable version published by n8n at install time, and write it down. Do not use the latest tag in production: a major update could apply on the next restart without you deciding it.

The variables that matter

VariableRolePitfall
N8N_ENCRYPTION_KEYEncrypts the credentials saved in n8nIf it changes or gets lost, every credential becomes unreadable. Back it up separately.
WEBHOOK_URLPublic URL used for webhooksMissing behind a proxy: webhooks show localhost and don't work.
N8N_HOST, N8N_PROTOCOLEditor hostname and protocolInconsistent with the proxy: broken redirects and cookies.
N8N_PROXY_HOPSNumber of proxies in front of n8nWrong value: IP addresses and protocol misread.
GENERIC_TIMEZONETime zone for schedules and datesForgotten: schedules fire on the default time zone, America/New_York.
EXECUTIONS_DATA_MAX_AGEHow long history is kept (hours)Too short: impossible to analyze a flow's rhythm.

The full list and use cases are in our article n8n environment variables.

Step 3: HTTPS with a reverse proxy

n8n does not handle certificates itself. You put a reverse proxy in front of it to terminate HTTPS. The simplest is Caddy, which obtains and renews Let's Encrypt certificates automatically. Add to the compose file:

  caddy:
    image: caddy:2
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - caddy_data:/data
# (add caddy_data to the volumes section)

And a Caddyfile:

n8n.example.com {
    reverse_proxy n8n:5678
}

In this setup, remove the publication of port 5678 on the host: only Caddy should be exposed. Traefik and Nginx work too; what matters is that proxy headers are forwarded and that N8N_PROXY_HOPS matches.

Step 4: secure the instance

  • Create the owner account right after first start, with a strong password, and turn on two-factor authentication.
  • Never publish the editor without HTTPS.
  • Authenticate your webhooks (header, basic auth or token): a public webhook without checks accepts any call.
  • Keep secrets in n8n credentials, not hard-coded in nodes. Since n8n 2.0, access to environment variables from the Code node is blocked by default.
  • Do not leave /metrics publicly accessible if you enable it.
  • Update regularly: n8n publishes security fixes, some of them critical in 2026.

Step 5: back up

Two things are essential to restore an n8n instance: the database and the encryption key. A database backup without the key does not let you recover credentials.

# Daily database backup (schedule with cron)
docker compose exec -T postgres pg_dump -U n8n n8n | gzip > /backups/n8n-$(date +%F).sql.gz

Copy backups off the server, and test a restore at least once. A backup that has never been restored is a hypothesis.

Step 6: update

  1. Read the release notes between your version and the target, especially breaking changes.
  2. Back up the database.
  3. Change the image version number in compose.yml.
  4. docker compose pull && docker compose up -d
  5. Check the logs, the editor, and that critical workflows run.

The details, with the recommended update strategy, are in Updating n8n without breaking things.

Step 7: monitor

Your instance is running; now you need to know it will still be running tomorrow, and that your workflows are doing their job. Three levels:

  1. The instance: an external check on https://n8n.example.com/healthz/readiness, which verifies that n8n responds and the database is connected.
  2. Failures: a shared error workflow, set in every production workflow.
  3. Silences, volumes and slowdowns: external monitoring that compares each workflow with its usual rhythm.

The complete guide to monitoring n8n details each level. Nokto covers all three with a simple API key, from outside your server.

Reverse proxyCaddy, Traefik, Nginxn8n maineditor, API, schedulesn8n webhookreceives callsn8n workersexecutions (queue mode)Redisexecution queuePostgreSQLworkflows, historyNoktopublic API + /healthzSelf-hosted n8n in production (queue mode)Nokto reads n8n's public API from the outside: nothing to install on the instance
When volume grows: queue mode with Redis and workers, and external monitoring reading the API

What's next: queue mode

When a single instance is no longer enough (many concurrent executions, long workflows, AI agents), n8n offers queue mode: the main instance receives triggers and places executions in a Redis queue, workers process them in parallel, and dedicated processes can receive webhooks. It is the production architecture for high volume. You set it up with EXECUTIONS_MODE=queue, a Redis service and worker containers started with the worker command. Our production checklist details what to watch out for.

Frequently asked questions

How do I install n8n locally?

With Docker: create a volume (docker volume create n8n_data), run docker run -it --rm --name n8n -p 5678:5678 -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n, then open http://localhost:5678 in your browser. Without Docker, n8n can also be installed with Node.js (npx n8n), but Docker is easier to maintain.

Does n8n need PostgreSQL?

Not to try it: n8n uses SQLite by default. For production, PostgreSQL is recommended: it handles load better, backups are easier to automate, and it is required for queue mode with several workers.

Why do my webhook URLs show localhost?

Because n8n does not know its public address. Set the WEBHOOK_URL variable to the instance's public URL (for example https://n8n.example.com/) and restart the container. The URLs shown in Webhook nodes will then use that address.

How do I update n8n installed with docker compose?

Change the image version number in the compose file, back up the database, then run docker compose pull and docker compose up -d. Read the release notes first, especially for a major version change.

What machine does n8n need?

For moderate use, 2 vCPUs and 4 GB of RAM are usually enough. Workflows that handle large files, AI agents and high volume need more; queue mode then lets you spread the load across several workers.

Sources

Try Nokto for free