Problem when upgrading the base image (with Python)

Describe the problem/error/question

Hello,

I’m trying to extend the base node to use Python, but when I do that, the n8n instance resets (I lose all my settings, workflows, credentials, etc).

I tried to follow this post (Python script through `execute command` - #9 by MutedJam) to include Python as part of the base node as I am a prolific Python developer, but not as much as a Javascript/TS one :slight_smile:

Everything works fine, I can call my Python scripts from /data/py_scripts and install new packages via requirements.txt, however, when I’m upgrading the base image (let’s say I start with 1.0.5 and I upgrade to 1.1.0 or even the most recent one (1.4.1)) the whole n8n instance is resetting like it’s not saving any information into the database (or other places used to preserve settings, workflows, credentials, etc).
This happens after each image upgrade (done via the Dockerfile by increasing the n8n release number).

What is the error message (if any)?

While n8n starts running, I also notice this in the console log, but I don’t think it’s related to the problem I’ve mentioned. Also, I noticed this message shows for n8n releases 1.2.0 and up, not before that:

n8n-python  | RangeError: Invalid status code: 1008
n8n-python  |     at new NodeError (node:internal/errors:399:5)
n8n-python  |     at ServerResponse.writeHead (node:_http_server:344:11)
n8n-python  |     at ServerResponse.writeHead (/usr/local/lib/node_modules/n8n/node_modules/on-headers/index.js:44:26)
n8n-python  |     at ServerResponse._implicitHeader (node:_http_server:335:8)
n8n-python  |     at ServerResponse.end (/usr/local/lib/node_modules/n8n/node_modules/compression/index.js:103:14)
n8n-python  |     at ServerResponse.send (/usr/local/lib/node_modules/n8n/node_modules/express/lib/response.js:232:10)
n8n-python  |     at Push.handleRequest (/usr/local/lib/node_modules/n8n/dist/push/index.js:37:30)
n8n-python  |     at /usr/local/lib/node_modules/n8n/dist/push/index.js:101:68
n8n-python  |     at newFn (/usr/local/lib/node_modules/n8n/node_modules/express-async-errors/index.js:16:20)
n8n-python  |     at Layer.handle [as handle_request] (/usr/local/lib/node_modules/n8n/node_modules/express/lib/router/layer.js:95:5)

Here are my files:
Dockerfile:

FROM n8nio/n8n:latest

ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 curl
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools

docker-compose.yaml

version: '3.8'

services:
  n8n:
    image: n8n-python
    restart: always
    container_name: n8n-python
    environment:
      GENERIC_TIMEZONE: ${TIMEZONE}
      TZ: ${TIMEZONE}
    ports:
      - "5678:5678"
    volumes:
      - ./n8n_data:/home/node/.n8n
      - ./local-files:/data/files # by default workdir == /data
      - ./python_scripts:/data/py_scripts
      - ./requirements.txt:/data/requirements.txt

After each change to the Dockerfile (again, I started with something low as 1.0.5 and moved up to the latest release) I run: docker build -t n8n-python && docker compose up (I don’t run it in detached mode to watch for the console errors).

Here’s the output of docker compose up:

[+] Running 1/0
 ✔ Container n8n-python  Recreated                                                                                                           0.1s
Attaching to n8n-python
n8n-python  | UserSettings were generated and saved to: /root/.n8n/config
n8n-python  | n8n ready on 0.0.0.0, port 5678
n8n-python  | Migrations in progress, please do NOT stop the process.
n8n-python  | Initializing n8n process
n8n-python  | Version: 1.2.0
n8n-python  |
n8n-python  | Editor is now accessible via:
n8n-python  | http://localhost:5678/
n8n-python  |
n8n-python  | RangeError: Invalid status code: 1008
n8n-python  |     at new NodeError (node:internal/errors:399:5)
n8n-python  |     at ServerResponse.writeHead (node:_http_server:344:11)
n8n-python  |     at ServerResponse.writeHead (/usr/local/lib/node_modules/n8n/node_modules/on-headers/index.js:44:26)
n8n-python  |     at ServerResponse._implicitHeader (node:_http_server:335:8)
n8n-python  |     at ServerResponse.end (/usr/local/lib/node_modules/n8n/node_modules/compression/index.js:103:14)
n8n-python  |     at ServerResponse.send (/usr/local/lib/node_modules/n8n/node_modules/express/lib/response.js:232:10)
n8n-python  |     at pushValidationMiddleware (/usr/local/lib/node_modules/n8n/dist/push/index.js:94:34)

The RangeError: Invalid status code: 1008 message keeps on repeating every few seconds.

Expected behavior:
I expected to upgrade n8n without losing workflows or credentials.
After upgrading, the first screen prompts to create a new account, like it’s a fresh install.

I’m sure I am missing something but I’m not sure what.

Thanks for your help!

Information on your n8n setup

  • **n8n version:1.0.5 through 1.4.1
  • **Database (default: SQLite):SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):docker
  • **Operating system:Mac OS and Ubuntu 22.04

same error

same problem…

is there a solution?

In my case, was a SSL issue.

I removed a vhost, re-entered it and requested a new SSL.

1 Like

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

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.