TechBuzzPro

Install n8n Docker: Step-by-Step Guide

· 6 min read · Apps & Browsers

In this article
  1. What Is n8n and Why Use Docker?
  2. Prerequisites for Docker Installation
  3. Basic Docker Run Command
  4. Using Docker Compose for a Persistent Setup
  5. Upgrading and Managing Your Container
  6. Common Problems and How to Fix Them
  7. Security Considerations for Self-Hosted n8n
  8. Alternative Installation Methods
  9. Frequently Asked Questions

Yes, you can install n8n using Docker, and it’s the recommended method for most self-hosted deployments. This guide walks you through the exact commands, configuration options, and common pitfalls so you can get a production-ready n8n instance running in minutes.

What Is n8n and Why Use Docker?

n8n is a fair-code workflow automation tool that lets you connect apps and services without writing code. It’s often described as a self-hosted alternative to Zapier or Make. Running it via Docker bundles the application, its runtime, and dependencies into a single container, which simplifies installation, upgrades, and scaling. Docker also isolates n8n from your host system, so you can experiment freely without polluting your main OS.

Prerequisites for Docker Installation

Before you start, you need:

  • A server or computer with a 64-bit Linux distribution (Ubuntu, Debian, CentOS) or Windows/macOS with Docker Desktop.
  • Docker Engine installed (version 20.10 or later) and Docker Compose (v2) for multi-container setups.
  • At least 1 GB of RAM and 2 GB of free disk space for a basic setup.
  • Port 5678 free on your host, as n8n’s web interface uses it by default.
  • Optional: a domain name and reverse proxy (like Nginx or Traefik) if you want HTTPS access.

If you’re on Linux, install Docker using your package manager. For example, on Ubuntu: sudo apt update && sudo apt install docker.io docker-compose-v2. Then enable the service with sudo systemctl enable --now docker.

Basic Docker Run Command

The simplest way to launch n8n is with a single docker run command. This starts a container named n8n that stores its data in a Docker volume called n8n_data.

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

Let’s break down the flags:

  • -d runs the container in the background (detached).
  • --name n8n gives the container a predictable name for management.
  • -p 5678:5678 maps the container’s port 5678 to the same port on your host.
  • -v n8n_data:/home/node/.n8n persists n8n’s database and files in a named volume. Without this, you’d lose all workflows when the container is removed.

After running, open http://localhost:5678 in your browser. You’ll see the n8n setup screen where you create an admin account. That’s it—you have a working instance.

Using Docker Compose for a Persistent Setup

For a more maintainable deployment, especially if you plan to add a database or reverse proxy, use Docker Compose. Create a directory (e.g., n8n) and a docker-compose.yml file with this content:

version: "3.8"
services:
  n8n:
    image: docker.n8n.io/n8nio/n8n
    container_name: n8n
    restart: unless-stopped
    ports:
      - "5678:5678"
    environment:
      - N8N_HOST=yourdomain.com  # replace with your domain or IP
      - N8N_PROTOCOL=https       # if using a reverse proxy with TLS
      - N8N_PORT=5678
      - N8N_SECURE_COOKIE=false  # set true if using HTTPS
    volumes:
      - n8n_data:/home/node/.n8n
volumes:
  n8n_data:

Then run docker compose up -d in that directory. The restart: unless-stopped policy ensures n8n starts automatically after a reboot or crash. The environment variables N8N_HOST, N8N_PROTOCOL, and N8N_SECURE_COOKIE are crucial when you expose n8n beyond localhost—they affect webhook URLs and cookie security.

Upgrading and Managing Your Container

Upgrading n8n is straightforward with Docker. To update to the latest version:

  1. Pull the new image: docker pull docker.n8n.io/n8nio/n8n
  2. Stop the running container: docker stop n8n
  3. Remove the old container: docker rm n8n
  4. Start a new container with the same volume and port mapping (or run docker compose up -d if using Compose).

Your workflows and credentials remain intact because they live in the volume. To see logs, use docker logs n8n; to stop, docker stop n8n; to remove the container but keep data, docker rm n8n. If you ever want a completely clean slate, delete the volume with docker volume rm n8n_data—but only after exporting your workflows.

Common Problems and How to Fix Them

Here are frequent issues you might hit and their solutions:

  • Port already in use: If you get “bind: address already in use,” another service is using 5678. Change the host port, e.g., -p 8080:5678, and access n8n at http://localhost:8080.
  • Permission denied when accessing /var/run/docker.sock: On Linux, add your user to the docker group with sudo usermod -aG docker $USER, then log out and back in. Or run commands with sudo.
  • Data loss after container restart: This almost always means you didn’t mount a volume. Always include -v n8n_data:/home/node/.n8n or a host directory like -v /path/on/host:/home/node/.n8n.
  • Webhooks not working behind a reverse proxy: Set N8N_HOST to your public domain and N8N_PROTOCOL=https. Also ensure your proxy forwards the Host header and WebSocket upgrades.
  • Slow performance on small VPS: n8n is Node.js-based and can be memory-hungry. Increase your server’s RAM or use an external database (PostgreSQL) for large workloads—but that’s an advanced setup.

Security Considerations for Self-Hosted n8n

Self-hosting means you’re responsible for security. At minimum, you should:

  • Change the default admin password immediately after first login.
  • Enable HTTPS via a reverse proxy (Caddy, Nginx, or Traefik) with Let’s Encrypt certificates. Never expose n8n over plain HTTP on the public internet.
  • Use environment variables to set a custom encryption key for credentials: N8N_ENCRYPTION_KEY (generate a random 32-character string). This protects your stored API keys and passwords.
  • Restrict access to the n8n port using a firewall (e.g., ufw allow 5678/tcp only from your IP, or use a VPN).
  • Keep n8n updated regularly to receive security patches.

If you’re only testing locally, you can skip HTTPS, but never expose an unsecured instance to the internet.

Alternative Installation Methods

Docker isn’t the only way to run n8n. You can also:

  • npm: Install globally with npm install n8n -g, then run n8n start. This requires Node.js 18+ and is less isolated.
  • Desktop app: n8n offers a desktop application for Windows, macOS, and Linux, suitable for local experimentation without a server.
  • Cloud service: n8n Cloud is the official hosted option—no maintenance, but you don’t control the infrastructure.

Docker remains the best balance of control and convenience for most self-hosters because it handles dependencies and updates cleanly.

Frequently Asked Questions

Do I need Docker Compose for n8n?

No, a single docker run works fine for basic use. Compose is only necessary if you want to define multiple services (like a database or reverse proxy) in one file, or if you prefer declarative configuration that’s easier to version-control.

How do I access n8n from another computer on my network?

Use your server’s IP address instead of localhost, e.g., http://192.168.1.100:5678. Ensure your firewall allows incoming connections on port 5678. For internet access, you’ll need port forwarding on your router and a domain name with HTTPS.

Can I use a different port for n8n?

Yes. Change the left side of the port mapping, e.g., -p 8080:5678. You’ll access n8n at http://localhost:8080. If you change the internal port (right side), you must also set N8N_PORT to match.

How do I back up my n8n data?

Back up the Docker volume. For a named volume, use docker run --rm -v n8n_data:/data -v $(pwd):/backup alpine tar czf /backup/n8n_backup.tar.gz -C /data .. Alternatively, if you mounted a host directory, just copy that folder. Restore by extracting the archive into the same volume or directory.

Why is n8n not starting after a reboot?

If you used docker run without --restart unless-stopped, the container won’t start automatically. Add that flag, or use Docker Compose with the restart policy as shown above. Also check that Docker itself is enabled with systemctl enable docker.