Operations 8 min read

Deploy n8n with Docker: Fast Setup, Production Config, and Database Guide

This guide explains what n8n is, compares it with Coze and Dify, and provides step‑by‑step instructions for quick installation via npx or Docker, detailed multi‑stage Dockerfile, production environment settings, database, SSL, Redis, monitoring, and backup strategies for reliable workflow automation.

Efficient Ops
Efficient Ops
Efficient Ops
Deploy n8n with Docker: Fast Setup, Production Config, and Database Guide

What is n8n?

n8n is a powerful workflow automation platform designed for technical teams that need both code flexibility and no‑code speed. It uses a modern monorepo architecture, offers over 400 integrations, native AI features, and deployment options for organizations of any size.

Image
Image

Choosing between Coze, n8n, and Dify

Coze : like fast‑food, create a chatbot in 5 minutes.

n8n : modular and flexible, but requires some hands‑on work.

Dify : gourmet‑level, but you must provide your own model.

Quick Installation Methods

Method 1: npx (recommended for testing)

The fastest way to try n8n is with npx, requiring Node.js 22.16 or newer:

npx n8n

Method 2: Docker (for production)

Docker provides isolation and reproducibility for production or consistent development environments.

docker volume create n8n_data  
# Run n8n with persistent data
docker run -it --rm \
  --name n8n \
  -p5678:5678 \
  -v n8n_data:/home/node/.n8n \
  docker.n8n.io/n8nio/n8n

Production Environment Configuration

The Docker image uses a multi‑stage build:

ARG NODE_VERSION=22.18.0
ARG N8N_VERSION=snapshot
ARG LAUNCHER_VERSION=1.4.0
ARG TARGETPLATFORM

# ============================================================================== 
# STAGE 1: System Dependencies & Base Setup 
# ============================================================================== 
FROM n8nio/base:${NODE_VERSION} AS system-deps  

# ============================================================================== 
# STAGE 2: Application Artifact Processor 
# ============================================================================== 
FROM alpine:3.22.0 AS app-artifact-processor  
COPY ./compiled /app/  

# ============================================================================== 
# STAGE 3: Task Runner Launcher 
# ============================================================================== 
FROM alpine:3.22.0 AS launcher-downloader  
ARG TARGETPLATFORM  
ARG LAUNCHER_VERSION  

RUN set -e; \
    case "$TARGETPLATFORM" in \
        "linux/amd64") ARCH_NAME="amd64" ;; \
        "linux/arm64") ARCH_NAME="arm64" ;; \
        *) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \
    esac; \
    mkdir /launcher-temp && cd /launcher-temp; \
    wget -q "https://github.com/n8n-io/task-runner-launcher/releases/download/${LAUNCHER_VERSION}/task-runner-launcher-${LAUNCHER_VERSION}-linux-${ARCH_NAME}.tar.gz"; \
    wget -q "https://github.com/n8n-io/task-runner-launcher/releases/download/${LAUNCHER_VERSION}/task-runner-launcher-${LAUNCHER_VERSION}-linux-${ARCH_NAME}.tar.gz.sha256"; \
    echo "$(cat task-runner-launcher-${LAUNCHER_VERSION}-linux-${ARCH_NAME}.tar.gz.sha256)  task-runner-launcher-${LAUNCHER_VERSION}-linux-${ARCH_NAME}.tar.gz" > checksum.sha256; \
    sha256sum -c checksum.sha256; \
    mkdir -p /launcher-bin; \
    tar xzf task-runner-launcher-${LAUNCHER_VERSION}-linux-${ARCH_NAME}.tar.gz -C /launcher-bin; \
    cd / && rm -rf /launcher-temp  

# ============================================================================== 
# STAGE 4: Final Runtime Image 
# ============================================================================== 
FROM system-deps AS runtime  
ARG N8N_VERSION  
ARG N8N_RELEASE_TYPE=dev  
ENV NODE_ENV=production  
ENV N8N_RELEASE_TYPE=${N8N_RELEASE_TYPE}  
ENV NODE_ICU_DATA=/usr/local/lib/node_modules/full-icu  
ENV SHELL=/bin/sh  

WORKDIR /home/node  

COPY --from=app-artifact-processor /app /usr/local/lib/node_modules/n8n  
COPY --from=launcher-downloader /launcher-bin/* /usr/local/bin/  
COPY docker/images/n8n/docker-entrypoint.sh /  
COPY docker/images/n8n/n8n-task-runners.json /etc/n8n-task-runners.json  

RUN cd /usr/local/lib/node_modules/n8n && \
    npm rebuild sqlite3 && \
    ln -s /usr/local/lib/node_modules/n8n/bin/n8n /usr/local/bin/n8n && \
    mkdir -p /home/node/.n8n && \
    chown -R node:node /home/node  

RUN cd /usr/local/lib/node_modules/n8n/node_modules/pdfjs-dist && npm install @napi-rs/canvas  

EXPOSE 5678/tcp  
USER node  
ENTRYPOINT ["tini","--","/docker-entrypoint.sh"]  

LABEL org.opencontainers.image.title="n8n" \
      org.opencontainers.image.description="Workflow Automation Tool" \
      org.opencontainers.image.source="https://github.com/n8n-io/n8n" \
      org.opencontainers.image.url="https://n8n.io" \
      org.opencontainers.image.version=${N8N_VERSION}

Key Docker Features

Security: runs as non‑root user with proper file permissions.

Custom certificates: support via /opt/custom-certificates.

Task runner integration: includes launcher for distributed execution.

Production optimization: NODE_ENV=production.

Database Configuration

n8n supports multiple database back‑ends; for PostgreSQL production deployment:

// Core PostgreSQL configuration
@Config
class PostgresConfig {
  @Env('DB_POSTGRESDB_DATABASE')
  database: string = 'n8n';

  @Env('DB_POSTGRESDB_HOST')
  host: string = 'localhost';

  @Env('DB_POSTGRESDB_PORT')
  port: number = 5432;

  @Env('DB_POSTGRESDB_POOL_SIZE')
  poolSize: number = 2;
}

SSL Configuration

PostgreSQL SSL connections are fully supported with comprehensive options:

@Config
class PostgresSSLConfig {
  @Env('DB_POSTGRESDB_SSL_ENABLED')
  enabled: boolean = false;

  @Env('DB_POSTGRESDB_SSL_CA')
  ca: string = '';

  @Env('DB_POSTGRESDB_SSL_CERT')
  cert: string = '';

  @Env('DB_POSTGRESDB_SSL_KEY')
  key: string = '';
}

Redis Configuration

Redis integration provides caching and session management for scalable production:

@Config
export class RedisConfig {
  /** Prefix for all Redis keys managed by n8n. */
  @Env('N8N_REDIS_KEY_PREFIX')
  prefix: string = 'n8n';
}

Database Connection Variables

Database connection variables
Database connection variables

Monitoring and Logging

Enable database query logging for performance monitoring:

DB_LOGGING_ENABLED=true
DB_LOGGING_OPTIONS=all
DB_LOGGING_MAX_EXECUTION_TIME=1000
DB_POSTGRESDB_PASSWORD   secure_password   # database password

Backup Strategy

Regular database backups (daily recommended for production).

Version control for configuration files.

Workflow export backups.

Redis persistence configuration.

Redisworkflow automationPostgreSQLProduction Deploymentn8n
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.