n8n / Dockerfile
prasad2134's picture
Upload 2 files
c4265d3 verified
Raw
History Blame Contribute Delete
1.26 kB
# ===========================================
# n8n on Hugging Face Spaces - Free Hosting
# ===========================================
FROM node:22-alpine
# Install build dependencies + n8n + wget for self-ping
RUN apk add --no-cache tini python3 make g++ wget && \
npm install -g n8n@2.17.7 && \
apk del python3 make g++ && \
mkdir -p /home/node/.n8n && \
chown -R node:node /home/node/.n8n
USER node
# ---- Port & Host ----
ENV N8N_PORT=7860
ENV N8N_HOST=0.0.0.0
# ---- Force IPv4 (HF Spaces doesn't support IPv6) ----
ENV NODE_OPTIONS=--dns-result-order=ipv4first
# ---- Production Mode ----
ENV NODE_ENV=production
ENV N8N_PROXY_HOPS=1
# ---- Database: PostgreSQL ----
ENV DB_TYPE=postgresdb
ENV DB_POSTGRESDB_DATABASE=postgres
ENV DB_POSTGRESDB_PORT=5432
ENV DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED=false
# ---- Disable diagnostics ----
ENV N8N_DIAGNOSTICS_ENABLED=false
ENV N8N_PERSONALIZATION_ENABLED=false
EXPOSE 7860
ENTRYPOINT ["tini", "--"]
# Self-ping script to prevent Hugging Face from sleeping the space (keeps it active)
# Pings localhost:7860 every 4 minutes (240s) in the background, then starts n8n
CMD sh -c "while true; do sleep 240; wget -q -O /dev/null http://localhost:7860/ 2>/dev/null; done & n8n start"