Home » n8n» Run n8n on Docker — Beginner Docker Compose Guide

Run n8n on Docker?

You can Run n8n on Docker using a simple Docker Compose file and persistent storage. This guide gives a clear, step-by-step setup for n8n automation on Docker. It shows how to start, update, and secure a self-hosted n8n instance.

What You Need

  • Docker and Docker Compose installed on your server or laptop.
  • A basic shell or terminal and a text editor.
  • Optional: Node.js if you plan to build custom nodes locally.
  • A folder for persistent data and backups.

Run n8n on Docker with Docker Compose

Follow these numbered steps to get n8n running with persistent storage and basic authentication. The commands work on Linux, macOS, and Windows with Docker Desktop.

Step 1: Create a folder

Make a project folder and enter it. Keep the n8n data in a local volume.

mkdir n8n-docker
cd n8n-docker

Step 2: Create a docker-compose.yml

Create a docker-compose.yml file with the official image and a volume for /home/node/.n8n. Set basic auth for quick protection.

version: '3.7'
services:
  n8n:
    image: n8nio/n8n:latest
    restart: unless-stopped
    ports:
      - "5678:5678"
    environment:
      - N8N_HOST=localhost
      - N8N_PORT=5678
      - N8N_PROTOCOL=http
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=changeme
    volumes:
      - ./n8n:/home/node/.n8n

Replace the user and password before exposing the port on a public server.

Step 3: Start n8n

Start the container in detached mode. This pulls the image and runs the service.

docker compose up -d

To view logs:

docker compose logs -f n8n

Step 4: Verify and open the UI

Open http://your-server-ip:5678 in a browser. Log in with the credentials you set. Your workflows and credentials are stored in the ./n8n folder.

Step 5: Optional – Use Postgres for production

For production, run Postgres and set environment variables to point n8n to the database. This improves reliability for many workflows.

services:
  postgres:
    image: postgres:14
    environment:
      - POSTGRES_USER=n8n
      - POSTGRES_PASSWORD=secret
    volumes:
      - pgdata:/var/lib/postgresql/data

  n8n:
    image: n8nio/n8n:latest
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_USER=n8n
      - DB_POSTGRESDB_PASSWORD=secret
    depends_on:
      - postgres

volumes:
  pgdata:

Update

To update n8n, pull the new image and restart. Back up your ./n8n folder first.

docker compose pull
docker compose up -d

If you change the image tag, recreate the containers after pulling.


Security

  • Use a reverse proxy with TLS (for example, Traefik or nginx with Let’s Encrypt).
  • Enable strong passwords or OAuth for production. Do not use default credentials.
  • Run the service behind a firewall and close unused ports.
  • Keep Docker and images updated. Use least privilege for host volumes.
  • Consider using Postgres and secure backups for critical data.

Done

You now run n8n on Docker with persistent data and basic protection. Use the UI to build automation workflows. For production, add TLS and a managed database.

Neil
Written by Neil

Neil is a true n8n geek who lives and breathes workflow automation. He dives deep into nodes, triggers, webhooks, custom logic, and self-hosting setups, sharing everything he learns about n8n on AutomationCompare.com. As part of a broader team of automation specialists, Neil focuses purely on mastering n8n and helping others unlock its full potential.

Keep Reading

Scroll to Top