n8n / Dockerfile
Amansoni7477030's picture
Update Dockerfile
e983431 verified
# Use PostgreSQL as the base image
FROM postgres:latest
# Set build-time variables
ARG DUMP_URL
ARG DUMP_PASSWORD
ARG POSTGRES_USER=n8n
ARG POSTGRES_PASSWORD=n8n
ARG POSTGRES_DB=n8n
#ARG WEBHOOK_URL=https://aigenai-db.hf.space/
ARG WORKDIR=/app
ARG DB_IMPORT=no
ARG NODEJS_VER=20
ARG NODE_PACKAGES="n8n"
ARG PYTHON_PACKAGES="requests yt-dlp"
# Set environment variables
ENV POSTGRES_USER=${POSTGRES_USER} \
POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \
POSTGRES_DB=${POSTGRES_DB} \
# WEBHOOK_URL=${WEBHOOK_URL} \
DB_IMPORT=${DB_IMPORT} \
N8N_HOST=0.0.0.0 \
N8N_PORT=7860 \
N8N_PROTOCOL=https \
GENERIC_TIMEZONE=Asia/Shanghai \
N8N_METRICS=true \
QUEUE_HEALTH_CHECK_ACTIVE=true \
N8N_PAYLOAD_SIZE_MAX=256 \
DB_TYPE=postgresdb \
DB_POSTGRESDB_HOST=localhost \
DB_POSTGRESDB_PORT=5432 \
DB_POSTGRESDB_USER=${POSTGRES_USER} \
DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD} \
DB_POSTGRESDB_DATABASE=${POSTGRES_DB} \
VIRTUAL_ENV=$WORKDIR/venv \
PATH="$WORKDIR/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
# Install necessary packages, Node.js, Python, and set timezone
RUN apt-get update && apt-get install -y \
curl unzip gnupg build-essential sudo vim git procps lsof net-tools \
ca-certificates openssl tzdata python3 python3-venv python3-pip gosu \
htop jq wget lftp && \
# Install Node.js
curl -fsSL https://deb.nodesource.com/setup_${NODEJS_VER}.x | bash - && \
apt-get install -y nodejs && \
# Install global Node.js packages
npm install -g ${NODE_PACKAGES} && \
# Set timezone
ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
dpkg-reconfigure --frontend noninteractive tzdata && \
# Install rclone
curl https://rclone.org/install.sh | bash && \
# Clean up apt cache
apt-get clean && rm -rf /var/lib/apt/lists/* && \
# Set up Python virtual environment
python3 -m venv $VIRTUAL_ENV && \
$VIRTUAL_ENV/bin/pip install --upgrade pip && \
$VIRTUAL_ENV/bin/pip install ${PYTHON_PACKAGES}
# Set working directory and copy startup scripts
WORKDIR ${WORKDIR}
COPY run.sh ${WORKDIR}/run.sh
COPY import-db.sh ${WORKDIR}/import-db.sh
RUN chmod +x ${WORKDIR}/run.sh ${WORKDIR}/import-db.sh
# Change existing postgres user UID and GID to 1000
USER root
RUN usermod -u 1000 postgres && groupmod -g 1000 postgres && \
chown -R postgres:postgres /var/lib/postgresql && \
chown -R postgres:postgres /var/run/postgresql && \
chown -R postgres:postgres ${WORKDIR} && \
mkdir -p ${WORKDIR}/backups && chmod -R 775 ${WORKDIR}/backups
# Switch to postgres user
USER postgres
# Health check configuration
HEALTHCHECK --interval=120s --timeout=10s --start-period=10s --retries=3 \
CMD pg_isready && curl -f http://localhost:7860/HEALTHZ || exit 1
# Execute run.sh script when the container starts
CMD ["./run.sh"]