n8n / Dockerfile
Yussuy's picture
Create Dockerfile
3614979 verified
FROM node:24-alpine
# Set user to root for installation
USER root
# Arguments that can be passed at build time
ARG N8N_PATH=/usr/local/lib/node_modules/n8n
ARG BASE_PATH=/root/.n8n
ARG DATABASE_PATH=$BASE_PATH/database
ARG CONFIG_PATH=$BASE_PATH/config
ARG WORKFLOWS_PATH=$BASE_PATH/workflows
ARG LOGS_PATH=$BASE_PATH/logs
# Install system dependencies (for Web automation, databases, video processing)
RUN apk add --no-cache \
git \
python3 \
py3-pip \
make \
g++ \
build-base \
cairo-dev \
pango-dev \
chromium \
postgresql-client \
ffmpeg \
yt-dlp \
openssl \
busybox-extras \
curl \
bash \
unzip \
libaio
# Puppeteer/Chromium configuration
ENV PUPPETEER_SKIP_DOWNLOAD=true
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
# Install n8n globally (will install the latest stable version)
RUN npm install -g n8n
# Create necessary directories
RUN mkdir -p $DATABASE_PATH $CONFIG_PATH $WORKFLOWS_PATH $LOGS_PATH
# Set ownership to the 'node' user for security
RUN chown -R node:node $BASE_PATH
# Set owner and fix write permission for the working directory
RUN mkdir -p /data \
&& chown -R node:node /data
# Set working directory
WORKDIR /data
# Switch to non-root user for execution (CRITICAL FOR SECURITY)
USER node
# Start n8n
CMD ["n8n", "start"]