# 使用 PostgreSQL 作为基础镜像 FROM postgres:latest # 元数据 LABEL maintainer="B站ai来事 " LABEL version="2.0" LABEL description="Custom image with PostgreSQL, Node.js, and Python for n8n" # 构建参数 ARG WORKDIR=/app ARG NODEJS_VER=20 ARG NODE_PACKAGES="n8n" ARG PYTHON_PACKAGES="requests yt-dlp" # 环境变量 ENV POSTGRES_USER=n8n \ POSTGRES_PASSWORD=n8n \ POSTGRES_DB=n8n \ WEBHOOK_URL=https://aigenai-db.hf.space/ \ DB_IMPORT=no \ 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" # 安装依赖和设置环境 RUN apt-get update && apt-get install -y --no-install-recommends \ 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 && \ curl -fsSL https://deb.nodesource.com/setup_${NODEJS_VER}.x | bash - && \ apt-get install -y nodejs && \ npm install -g ${NODE_PACKAGES} && \ curl https://rclone.org/install.sh | bash && \ ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ dpkg-reconfigure --frontend noninteractive tzdata && \ python3 -m venv $VIRTUAL_ENV && \ $VIRTUAL_ENV/bin/pip install --no-cache-dir --upgrade pip && \ $VIRTUAL_ENV/bin/pip install --no-cache-dir ${PYTHON_PACKAGES} && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \ npm cache clean --force # 设置工作目录并复制启动脚本 WORKDIR ${WORKDIR} COPY run.sh ${WORKDIR}/run.sh COPY import-db.sh /docker-entrypoint-initdb.d/ RUN chmod +x ${WORKDIR}/run.sh /docker-entrypoint-initdb.d/import-db.sh # 设置用户和权限 RUN usermod -u 1000 postgres && groupmod -g 1000 postgres && \ chown -R postgres:postgres /var/lib/postgresql /var/run/postgresql ${WORKDIR} && \ mkdir -p ${WORKDIR}/backups && chmod -R 775 ${WORKDIR}/backups # 切换到 postgres 用户 USER postgres # 健康检查配置 HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD pg_isready && curl -f http://localhost:7860/HEALTHZ || exit 1 # 启动容器时执行 run.sh 脚本 CMD ["./run.sh"]