Problem when upgrading the base image (with Python)

I think I found the solution.
It had to do with permissions. Starting with n8n version 1, the app is running under the ‘node’ user instead of root for increased security.

Here are the Dockerfile and docker-compose.yaml that worked for me:

FROM n8nio/n8n:latest

USER root   # you need to specify the root user for installing/updating packages
WORKDIR /data   # this seem to fix the RangeError message I mentioned earlier
RUN apk add --update --no-cache python3 curl
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools

Build your image with:
docker build -t n8n-python .

Then, in your docker-compose.yaml, specify ‘node’ as the user running the n8n service:

version: '3.8'

services:
  n8n:
    image: n8n-python # the image you built with your Dockerfile
    user: "node" # specify 'node' as the user running the n8n service
    restart: unless-stopped
    container_name: n8n-python
    environment:
      GENERIC_TIMEZONE: ${TIMEZONE}
      TZ: ${TIMEZONE}
    ports:
      - "5678:5678"
    volumes:
      - ./n8n_data:/home/node/.n8n
      - ./local-files:/data/files
      - ./python_scripts:/data/py_scripts
      - ./requirements.txt:/data/requirements.txt

Don’t forget to specify your environment variables in the .env file, if needed.

By using this method I was able to upgrade the n8n releases while keeping my n8n data (credentials, workflows, etc.) intact.

2 Likes