n8n-space / Dockerfile
Avinyaa12's picture
Update Dockerfile
58995d2 verified
# Use Node.js 20 as base image (required for n8n)
FROM node:20-alpine
# Set up a new user named "user" with user ID 1000 (required for HF Spaces)
# Delete any existing user with UID 1000 and create our user
RUN getent passwd 1000 | cut -d: -f1 | xargs -r deluser && \
adduser -D -u 1000 user
# Set environment variables for n8n
ENV N8N_PORT=7860
ENV N8N_HOST=0.0.0.0
ENV N8N_PROTOCOL=https
ENV WEBHOOK_URL=https://Avinyaa12-n8n-space.hf.space
ENV N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=false
# Expose port 7860 for Hugging Face Spaces
EXPOSE 7860
# Create directories and set proper ownership
RUN mkdir -p /home/user/.n8n /home/user/.npm && \
chown -R user:user /home/user
# Set home to the user's home directory
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
# Set the working directory to the user's home directory
WORKDIR /home/user
# Switch to the "user" user
USER user
# Install n8n globally in user's home directory
RUN npm install -g n8n --prefix /home/user/.npm
# Add npm global bin to PATH
ENV PATH=/home/user/.npm/bin:$PATH
# Start n8n directly
CMD ["n8n", "start"]